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.
Y a-t-il un moyen d'obtenir l'adresse IP (V4) d'une interface dans le système de fichiers d'Android? Je sais que je pourrais utiliser ifconfig ou netcfg mais je voudrais utiliser un outil de surveillance qui ne peut accéder à des fichiers que et non exécuter des commandes.
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.
Selon Un post sur SO , cat /proc/net/tcp
le retournera dans
la deuxième colonne, avec la rubrique "local_address", par ex. "CF00A8C0: 0203".
la partie après ":" est un numéro de port.
à partir du reste, utilisez les deux derniers (C0) en tant que numéro hexagonal, par ex. C0 est 192, qui est le début de l'adresse dans cet exemple.
En outre:
L'adresse IP est affichée sous la forme d'un nombre hexadécimal de quatre octets à quatre octets; C'est-à-dire que l'octet le moins important est indiqué en premier, vous aurez donc besoin d'inverser l'ordre des octets pour la convertir en une adresse IP.
Le numéro de port est un simple numéro hexadécimal de deux octets.
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.
Je n'ai pas Android pour le tester, mais Linux offre:
cat /proc/net/fib_trie
.. de https: //unix.stackexchange.com/questions/365225/how-a-get-the-iPv4-Address-for-an-interface-de-proc
La sortie peut ensuite être filtrée plus loin par Grep, par exemple
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 www.demandez.top All Rights Reserved. Questions et réponses Accueil Tous les droits sont réservés