android手机usb共享后如何获取系统的ip地址? [英] How to get the system ip address after usb tethering of android phone?

查看:743
本文介绍了android手机usb共享后如何获取系统的ip地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在用android开发移动应用程序.
在这里,我想在任何Android手机的USB共享后检测计算机,系统等的IP地址
我找不到解决方案.
如果我输入以下代码,那么它将仅使用电话的IP地址,我需要系统的IP地址


I'm developing a mobile application in android.
Here I want to detect the IP address of the computer,system,etc after the usb tethering of the any android phone
I cannot find the solution.
If I put the following code then it takes the only the IP address of phone ,I need IP address of system

以下是代码

  ArrayList<InetAddress> arrayList=new ArrayList<InetAddress>();

        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    arrayList.add(inetAddress);
                    inetAddress=null;
                }
            }
        } catch (SocketException ex) {
            Log.e("SALMAN", ex.toString());
        }
        return arrayList;


请帮助我获取系统的IP地址,如果我们无法获取方法,请提及我.因为我是android新手.


Please help me to get the system's IP address,If we cannot able to get means so please mention me. Because I'm new to android.


我正在使用android 1.6.


在Windows XP系统中有服务器端应用程序.该应用程序是由C#.net开发的Windows服务.
该Windows服务侦听某个端口(例如234等).如果某些数据进入该端口,它将处理该数据并通过该端口发送响应.


I'm using android 1.6 .


There is server side application in the windows xp system. That application is a windows service which is developed by C# .net.
That windows service listen to some port such like 234,etc.If some data comes to port then it will process the data and send response through that port.


在android中,android应用程序通过套接字将数据发送到Windows服务.
将android手机通过USB绑定到运行Windows服务的系统.然后,系统假定android手机为调制解调器,并为系统生成了其他IP地址.当绑定android手机时,该IP地址是动态生成的.
对于通过套接字向系统移动的数据传输,我需要在我的android编码中提供系统的IP地址(系留后).
如果android编码中有任何方法可以获取此IP地址.
请大家就此提出您的想法.


In android the android application is send the data to the windows service via socket.
The android phone is USB tethered to the system in which windows service is running.Then system assume android phone is modem and additional IP address is generated for the system.This ip address is dynamically generated when the android phone is tethered.
For data transfer form mobile to system via socket .I will need to give the ip address of the system (after tethered) in my android coding.
If there is any method in android coding to get this IP address.
All are please give your ideas on regarding this.

推荐答案

绑定后,无法从android中找到在PC中创建的IP地址.没有API或其他方式可以找到它.

Its not possible to find IP address created in PC from android after tethering. There is no API or other way to find it.

如果使用InetAddress,它将返回192.168.42.129-这是由USB网络共享创建的DHCP地址.它不会帮助您交流.

If you use InetAddress , it will return 192.168.42.129 - which is a DHCP address created by USB Tethering. It wont help you to communicate.

另一种方法是扫描IP列表. USB网络共享将创建ip,范围从192.168.42.1到192.168.42.255.您可以编写一个简单的扫描仪以查找哪个扫描仪处于活动状态.但这需要一些时间.

The other way is to scan the list of IP. USB Tethering will create ip ranging for 192.168.42.1 to 192.168.42.255 . You can write a simple scanner to find which one is active. But it will take some time.

这篇关于android手机usb共享后如何获取系统的ip地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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