Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
			
				final AsyncAddressPhaseOne address = new AsyncAddressPhaseOne(textView);
				
                  ExecutorService service = Executors.newFixedThreadPool(5);
				
				service.execute(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						address.execute("");

					}
				});

			}

			
		});

	}

	private class AsyncAddressPhaseOne extends
	AsyncTask<string,> {

int Host;
TextView textView;

public AsyncAddressPhaseOne(TextView textView) {
	// TODO Auto-generated constructor stub

	this.textView = textView;
}

@Override
protected String doInBackground(String... arg0) {
	// TODO Auto-generated method stub

	System.out.print("Phase 1 Triggered\n");

	Host = 1;
	while (Host < 20) {
		try {
			final InetAddress in;
			in = InetAddress.getByName("192.168.1." + Host);
			if (in.isReachable(TimeOut)) {

				publishProgress("IP: 192.168.1." + Host + " Hostname: "
						+ in.getHostName());

			}else if(!in.getHostAddress().equals(in.getHostAddress())){
				publishProgress("192.168.1."+Host);
				
			}else 
				publishProgress(""+Host);
		} catch (UnknownHostException UHE) {
			System.out.println(UHE.toString());
			
		} catch (IOException IO) {
			System.out.println(IO.toString());
		}
		Host++;
	}

	return null;
}

@Override
protected void onProgressUpdate(final String... values) {
	// TODO Auto-generated method stub

	Handler handler = new Handler();

	handler.post(new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub

			textView.append(values[0].toString() + "\n");
		}
	});

	super.onProgressUpdate(values);
}

}


please help me i am really disturber /
Posted
Updated 4-Mar-14 4:19am
v2
Comments
Richard MacCutchan 1-Mar-14 4:21am    
Format your code properly with <pre> tags, and explain your problem clearly.

1 solution

Here is a function that can be used to list all your local IP:

Java
private static InetAddress[] GetAllIP() throws UnknownHostException
        {
                ArrayList addresses = new ArrayList();
                Enumeration e = null;
                try
                {
                        e = NetworkInterface.getNetworkInterfaces();
                }
                catch (SocketException ex)
                {
                        throw new UnknownHostException("127.0.0.1");
                }

                while (e.hasMoreElements())
                {
                        NetworkInterface ni = (NetworkInterface) e.nextElement();
                        for (Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements();)
                        {
  
                                addresses.add(e2.nextElement());
                        }
                }
                InetAddress[] iAddresses = new InetAddress[addresses.size()];
                for (int i = 0; i < iAddresses.length; i++)
                {
                        iAddresses[i] = (InetAddress) addresses.get(i);
                }
                return iAddresses;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900