是否有一种方法可以在Android文件系统中获取接口的IP(v4)地址?我知道我可以使用ifconfig或netcfg,但我想使用一个监控工具,只能只能访问文件而不是执行命令。
是否有一种方法可以在Android文件系统中获取接口的IP(v4)地址?我知道我可以使用ifconfig或netcfg,但我想使用一个监控工具,只能只能访问文件而不是执行命令。
Is there a way to get the IP (v4) address of an interface in the file system of Android? I know I could use ifconfig or netcfg but I would like to use a monitoring tool which can only access files and not execute commands.
根据帖子在SO ,<代码> ABCDEFGHIJKLMNABCDEFGHIJKLMN3 将在
中返回它第二列,标题"local_address" ,例如, "cf00a8c0:0203" 。
":" 之后的部分是端口号。
从剩下的时间使用最后两个(c0)作为十六进制号码,例如, C0是192,这是此示例中的地址的开始。
进一步:
IP地址显示为小端四字节十六进制数;也就是说,首先列出了最低有效字节,因此您需要反转字节字节的顺序以将其转换为IP地址。
端口号是一个简单的双字节十六进制数。
According to a post on SO, cat /proc/net/tcp
will return it in
the second column, with the heading "local_address", e.g. "CF00A8C0:0203".
The part after ":" is a port number.
From the rest use the last two (C0) as a hex number, e.g. C0 is 192, which is the start of the address in this example.
Further:
The IP address is displayed as a little-endian four-byte hexadecimal number; that is, the least significant byte is listed first, so you'll need to reverse the order of the bytes to convert it to an IP address.
The port number is a simple two-byte hexadecimal number.
我没有 android 测试它,但Linux优惠:
cat /proc/net/fib_trie
..从 https: //unix.stackexchange.com/questions/365225/how-to-get-the-ipv4-address-for-an-interface-from-proc
然后可以通过Grep,例如,通过Grep进一步过滤输出。 cat /proc/net/fib_trie|grep '|--' | grep -vE ' 127|.0[^0-9.]*$|.255[^0-9.]*$'
I have no Android to test it, but Linux offers:
cat /proc/net/fib_trie
.. from https://unix.stackexchange.com/questions/365225/how-to-get-the-ipv4-address-for-an-interface-from-proc
The output can then be filtered further by grep, e.g.
cat /proc/net/fib_trie|grep '|--' | grep -vE ' 127|\.0[^0-9.]*$|\.255[^0-9.]*$'
© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有