我无法得到所有IP地址neyer我的Android设备只有获取wifi连接的IP地址无法访问计算机的IP地址 [英] i can't get the all ip address neyer my android device only getting wifi connected ip address can't access the computer ip address

查看:89
本文介绍了我无法得到所有IP地址neyer我的Android设备只有获取wifi连接的IP地址无法访问计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 /

推荐答案

这是一个可以用来列出你所有本地IP的函数:



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

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;
        }


这篇关于我无法得到所有IP地址neyer我的Android设备只有获取wifi连接的IP地址无法访问计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆