获取使用USB网络共享创建的RNDIS adpater的IP?

时间:2021-12-21 06:36:12

when i connect an android device to a windows PC through USB tethering, it creates a network adpater, a Remote NDIS. This adapter's ip address, gateway etc values are set by android phone(i think). Is there a way to get these values in android code or app. The ip address here is dynamic(want keep it that way only, do not want to use STATIC ip), with this ip i want to send http request via usb cable to the pc or server.

当我通过USB网络共享将Android设备连接到Windows PC时,它会创建一个网络adpater,一个远程NDIS。这个适配器的IP地址,网关等值是由android手机设置的(我认为)。有没有办法在Android代码或应用程序中获取这些值。这里的ip地址是动态的(只想保持这种方式,不想使用STATIC ip),用这个ip我想通过USB线缆将http请求发送到PC或服务器。

1 个解决方案

#1


0  

If you want to find out the IP address of your phone in this connection you can use the following methods:

如果要在此连接中找到手机的IP地址,可以使用以下方法:

1) Install applications like "IP Tools" or "Ping Tools", which can display the current state of your network interfaces (check interface "rndis0").

1)安装“IP Tools”或“Ping Tools”等应用程序,它们可以显示网络接口的当前状态(检查接口“rndis0”)。

2) Connect the device to the computer and turn on the development mode (which will enable the ADB interface). Then use the adb command-line tool from your PC to access your device: adb shell ip addr. The following command will display the information about all your network interfaces. You need to check the network interface "rndis0".

2)将设备连接到计算机并打开开发模式(这将启用ADB接口)。然后使用PC上的adb命令行工具访问您的设备:adb shell ip addr。以下命令将显示有关所有网络接口的信息。您需要检查网络接口“rndis0”。

3) If you are the application developer you can use the class NetworkInterface (follow the link https://developer.android.com/reference/java/net/NetworkInterface.html).

3)如果您是应用程序开发人员,则可以使用NetworkInterface类(请访问链接https://developer.android.com/reference/java/net/NetworkInterface.html)。

4) Alternatively connect to the device via SSH (previously install the SSH server application) and use the commands like ip addr to find out the information about your network interfaces.

4)或者通过SSH连接到设备(以前安装SSH服务器应用程序)并使用ip addr等命令查找有关网络接口的信息。

Hope, this answer will help someone. :)

希望,这个答案会对某人有所帮助。 :)

#1


0  

If you want to find out the IP address of your phone in this connection you can use the following methods:

如果要在此连接中找到手机的IP地址,可以使用以下方法:

1) Install applications like "IP Tools" or "Ping Tools", which can display the current state of your network interfaces (check interface "rndis0").

1)安装“IP Tools”或“Ping Tools”等应用程序,它们可以显示网络接口的当前状态(检查接口“rndis0”)。

2) Connect the device to the computer and turn on the development mode (which will enable the ADB interface). Then use the adb command-line tool from your PC to access your device: adb shell ip addr. The following command will display the information about all your network interfaces. You need to check the network interface "rndis0".

2)将设备连接到计算机并打开开发模式(这将启用ADB接口)。然后使用PC上的adb命令行工具访问您的设备:adb shell ip addr。以下命令将显示有关所有网络接口的信息。您需要检查网络接口“rndis0”。

3) If you are the application developer you can use the class NetworkInterface (follow the link https://developer.android.com/reference/java/net/NetworkInterface.html).

3)如果您是应用程序开发人员,则可以使用NetworkInterface类(请访问链接https://developer.android.com/reference/java/net/NetworkInterface.html)。

4) Alternatively connect to the device via SSH (previously install the SSH server application) and use the commands like ip addr to find out the information about your network interfaces.

4)或者通过SSH连接到设备(以前安装SSH服务器应用程序)并使用ip addr等命令查找有关网络接口的信息。

Hope, this answer will help someone. :)

希望,这个答案会对某人有所帮助。 :)