Al probar una APLICACIÓN, el teléfono móvil debe usarse como un punto de acceso para esperar a que el dispositivo se conecte. Después de que el dispositivo esté conectado, use la APLICACIÓN para operar.
Para obtener el estado de la conexión WIFI del punto de acceso del teléfono móvil, verifiqué la información en línea y encontré los siguientes comandos para la verificación del estado de WIFI del teléfono móvil.
1. ¿El teléfono es un punto de acceso o WIFI?
WIFI tiene dos modos: AP y STA. AP es un punto de acceso y STA se utiliza como terminal para conectarse al punto de acceso.
Con el comando iw dev, si el teléfono móvil enciende el punto de acceso, el tipo de wlan0 es AP y ssid es el SSID
Si el teléfono está conectado a un determinado WIFI, se administra el tipo de wlan0 y ssid es el SSID del punto de acceso conectado
iw también puede ver y configurar mucha información sobre la capa física de la red y la capa de aplicación, pero este comando requiere
# iw dev
phy # 0
Interfaz p2p0
ifindex 27
wdev 0x2
addr XXXXXXXXXXXX
tipo P2P-device
Interfaz wlan0
ifindex 26
wdev 0x1
addr XXXXXXXXXXXX
ssid TEST
tipo AP
2. Verifique el WIFI conectado
Puede ver la conexión WIFI a través del comando cat / proc / net / arp.
Si el teléfono móvil es un hotspot WIFI, se consultará la información del terminal conectado al hotspot;
Si el teléfono móvil está conectado al punto de acceso WIFI, se consultará la dirección de la puerta de enlace del teléfono móvil;
Tenga en cuenta que cuando el campo Flags es 0x2, significa que la conexión es normal. Una vez desconectada la conexión, los Flags pasan a ser 0x0 (demora unos segundos). Si ejecuta ip neigh flush dev wlan0, la información de estado de ARP se puede actualizar inmediatamente (la conexión o desconexión se detecta inmediatamente).
Si la conexión WIFI se desconecta en el medio, la información de ARP no se borrará. Puede verificar el estado de la conexión actual a través de Banderas.
C: \ Windows \ System32> adb shell cat / proc / net / arp
Dirección IP Tipo de
hardware Indicadores Dirección de hardware Máscara Dispositivo 192.168.43.181 0x1 0x2 XXXXXXXXXXXX * wlan0
C: \ Windows \ System32> adb shell cat / proc / net / arp
Dirección IP Tipo de HW Banderas Dirección de HW Máscara Dispositivo
192.168.43.1 0x1 0x2 XXXXXXXXXXXX * wlan0
A través de ip neigh show, puede ver el estado en tiempo real de la conexión al punto de acceso WIFI. Cuando no hay conexión, la consulta de adb shell ip neigh show está vacía
Durante el proceso de conexión, el estado inicial es un estado INCOMPLETO breve, luego el estado RETARDO y el estado estable es ALCANZABLE.
C: \ Windows \ System32> adb shell ip neigh show
192.168.43.181 dev wlan0 lladdr 20: f4: 78: 09: 48: b3 DELAY
fe80 :: 22f4: 78ff: fe09: 48b3 dev wlan0 lladdr 20: f4: 78: 09 : 48: b3 DELAY
2409: 894c: 130: 10bc: d: 1b8e: e8ea: 3b2c dev wlan0 lladdr 20: f4: 78: 09: 48: b3 ALCANZABLE
C: \ Windows \ System32> adb shell ip neigh show
192.168.43.181 dev wlan0 lladdr 20: f4: 78: 09: 48: b3 REACHABLE
fe80 :: 22f4: 78ff: fe09: 48b3 dev wlan0 lladdr 20: f4: 78: 09 : 48: b3 ALCANZABLE
2409: 894c: 130: 10bc: d: 1b8e: e8ea: 3b2c dev wlan0 lladdr 20: f4: 78: 09: 48: b3 DELAY
La secuencia de cambio de estado después de la desconexión WIFI es: DELAY-> PROBE-> FAILED / INCOMPLETE
A veces en estado STALE
3. Cómo saber si la conexión WIFI está realmente desconectada
Las pruebas a largo plazo encontraron que cuando no hay tráfico en el WIFI (como el estado de la pantalla negra), puede ser por ahorro de energía u otras razones, y el estado de los pares consultado no es completamente exacto.
Por ejemplo, si usa el comando adb shell cat / proc / net / arp para realizar consultas, el par se ha conectado al punto de acceso. La mayor parte del estado consultado es 0x2 y una pequeña parte es 0x0, es decir, la conexión está desconectada. El juicio es completamente inexacto basado en este comando.
El uso del comando adb shell ip neigh show para ver es similar: el estado del extremo opuesto cambia entre ALCANZABLE / RETRASO / INCOMPLETO / ESTADO, y no se puede juzgar con precisión si el extremo opuesto se ha desconectado temporalmente.
Más tarde, pensé en una forma, primero hacer ping a la otra parte varias veces antes de consultar, si puede hacer ping, significa que funciona; de lo contrario, no funciona
adb shell ping -c 3 IPV4
4. Captura de paquetes WLAN0
Puede obtener la conexión de red del teléfono a través de tcpdump
tcpdump -i wlan0 -w /mnt/sdcard/Download/20200404.pcap
6. Verifique la recepción y envío de paquetes de WLAN0
# iw dev wlan0 station dump
Station XXXXXXXXXXXX (en wlan0)
paquetes rx: 3558
paquetes tx: 3355
tx reintentos: 170
tx fallaron: 6
# iw dev wlan0 station get XXXXXXXXXXXX
Station 20: f4: 78: 09: 48: b3 (en wlan0)
paquetes rx: 1035
paquetes tx: 982
reintentos tx: 29
tx fallado: 0
7. Potencia WLAN
# iw dev wlan0 get power_save Ahorro de
energía: activado
phy <phyname> set txpower <auto | fixed | limit> [<tx power in mBm>]
Especifica el nivel de potencia de transmisión y el tipo de configuración.
dev <devname> set txpower <auto | fixed | limit> [<tx power in mBm>]
Especifica el nivel de potencia de transmisión y el tipo de configuración.
8. Adquisición de dirección IP WLAN0
Obtenga la dirección IP a través del comando ifconfig wlan0, e inet addr es la dirección IPV4.
WLAN0 es un punto de acceso
# ifconfig wlan0 wlan0
Encap de enlace: Ethernet HWaddr XXXXXXXXXXXX Driver icnss
inet addr: 192.168.43.1 Bcast: 192.168.43.255 Máscara: 255.255.255.0
inet6 addr: fe80 :: b6c4: fcff: fe5c: 3d60 / 64 Alcance: Link
inet6 addr: 2409 : 894c: 130: 10bc :: 88/64 Alcance: Global
UP BROADCAST RUNNING MULTICAST MTU: 1500 Métrica: 1
paquetes RX: 0 errores: 0 descartados: 0 desbordamientos: 0 trama: 0
paquetes TX: 6419 errores: 0 descartados: 70 desbordamientos: 0 portadora: 0
colisiones: 0 txqueuelen: 3000
bytes RX: 0 bytes TX: 2586348
WLAN0 apagó el punto de acceso y la conexión WIFI
# ifconfig wlan0 wlan0
Encapsulación de enlace: Ethernet HWaddr XXXXXXXXXXXX Driver icnss
BROADCAST MULTICAST MTU: 1500 Métrica: 1
paquetes RX: 0 errores: 0 descartados: 0 desbordamientos: 0 trama: 0
paquetes TX: 6430 errores: 0 descartados: 70 desbordamientos: 0 portadora : 0
colisiones: 0 txqueuelen: 3000
bytes RX: 0 bytes TX: 2587230
WLAN0 apaga el hotspot, enciende WIFI pero no hay ningún hotspot conectado:
# ifconfig wlan0 wlan0
Encapsulado de enlace: Ethernet HWaddr XXXXXXXXXXXX Driver icnss
UP BROADCAST MULTICAST MTU: 1500 Métrica: 1
Paquetes RX: 446 errores: 0 descartados: 0 desbordamientos: 0 trama: 0
Paquetes TX: 7061 errores: 0 descartados: 70 desbordamientos: 0 portadora: 0
colisiones: 0 txqueuelen: 3000
RX bytes: 93909 TX bytes: 2794442
WLAN0 está conectado a un punto de acceso WIFI
# ifconfig wlan0 wlan0
Encapsulación de enlace: Ethernet HWaddr XXXXXXXXXXXX Controlador icnss
inet addr: 192.168.43.18 Bcast: 192.168.43.255 Máscara: 255.255.255.0
inet6 addr: fe80 :: b6c4: fcff: fe5c: 3d60 / 64 ALCANCE: Link
RUN BROADCAST MTU: 1500 Métrica: 1
paquetes RX: 54 errores: 0 descartados: 0 desbordamientos: 0 trama: 0
paquetes TX: 6501 errores: 0 descartados: 70 desbordamientos: 0 portadora: 0
colisiones: 0 txqueuelen: 3000
bytes RX: 8359 bytes TX : 2598189
9. Apéndice: el significado de ip neigh consultar el estado del par
http://manpages.ubuntu.com/manpages/eoan/man8/ip-neighbour.8.html
The ip neigh command manipulates neighbour objects that establish bindings between
protocol addresses and link layer addresses for hosts sharing the same link. Neighbour
entries are organized into tables. The IPv4 neighbour table is also known by another name
- the ARP table.
The corresponding commands display neighbour bindings and their properties, add new
neighbour entries and delete old ones.
ip neighbour add
add a new neighbour entry
ip neighbour change
change an existing entry
ip neighbour replace
add a new entry or change an existing one
These commands create new neighbour records or update existing ones.
to ADDRESS (default)
the protocol address of the neighbour. It is either an IPv4 or IPv6 address.
dev NAME
the interface to which this neighbour is attached.
proxy indicates whether we are proxying for this neigbour entry
router indicates whether neigbour is a router
extern_learn
this neigh entry was learned externally. This option can be used to indicate
to the kernel that this is a controller learnt dynamic entry. Kernel will
not gc such an entry.
lladdr LLADDRESS
the link layer address of the neighbour. LLADDRESS can also be null.
nud STATE
the state of the neighbour entry. nud is an abbreviation for 'Neighbour
Unreachability Detection'. The state can take one of the following values:
permanent
the neighbour entry is valid forever and can be only be removed
administratively.
noarp the neighbour entry is valid. No attempts to validate this entry will
be made but it can be removed when its lifetime expires.
reachable
the neighbour entry is valid until the reachability timeout expires.
stale the neighbour entry is valid but suspicious. This option to ip neigh
does not change the neighbour state if it was valid and the address
is not changed by this command.
none this is a pseudo state used when initially creating a neighbour entry
or after trying to remove it before it becomes free to do so.
incomplete
the neighbour entry has not (yet) been validated/resolved.
delay neighbor entry validation is currently delayed.
probe neighbor is being probed.
failed max number of probes exceeded without success, neighbor validation
has ultimately failed.
ip neighbour delete
delete a neighbour entry
The arguments are the same as with ip neigh add, except that lladdr and nud are
ignored.
Warning: Attempts to delete or manually change a noarp entry created by the kernel
may result in unpredictable behaviour. Particularly, the kernel may try to resolve
this address even on a NOARP interface or if the address is multicast or broadcast.
ip neighbour show
list neighbour entries
to ADDRESS (default)
the prefix selecting the neighbours to list.
dev NAME
only list the neighbours attached to this device.
vrf NAME
only list the neighbours for given VRF.
proxy list neighbour proxies.
unused only list neighbours which are not currently in use.
nud STATE
only list neighbour entries in this state. NUD_STATE takes values listed
below or the special value all which means all states. This option may occur
more than once. If this option is absent, ip lists all entries except for
none and noarp.
ip neighbour flush
flush neighbour entries
This command has the same arguments as show. The differences are that it does not
run when no arguments are given, and that the default neighbour states to be
flushed do not include permanent and noarp.
With the -statistics option, the command becomes verbose. It prints out the number
of deleted neighbours and the number of rounds made to flush the neighbour table.
If the option is given twice, ip neigh flush also dumps all the deleted neighbours.