我正在尝试编写一个批处理文件,当它连接到网络(Tenda WiFi路由器)时,应该找到我的
Android手机动态分配的IP.
所以我正在尝试使用arp -a并搜索我手机的MAC地址,以便从表中获取IP.
- C:\Users\Leeroy>arp -a
- Interface: 192.168.0.100 --- 0xb
- Internet Address Physical Address Type
- 192.168.0.1 c8-3a-35-35-f6-68 dynamic
- 192.168.0.255 ff-ff-ff-ff-ff-ff static
- 224.0.0.22 01-00-5e-00-00-16 static
- 224.0.0.251 01-00-5e-00-00-fb static
- 224.0.0.252 01-00-5e-00-00-fc static
- 239.255.255.250 01-00-5e-7f-ff-fa static
- 255.255.255.255 ff-ff-ff-ff-ff-ff static
问题是它没有出现在表中!我试过ping 192.168.0.255,但它仍然没有出现.我尝试从手机的浏览器请求192.168.0.100(我的桌面电脑的IP),这确实足以让手机上雷.但是每次我希望它出现在arp表中时,我都没有选择手动执行此操作.
如何让Android手机出现在arp表中(除了连接到WiFi之外没有做任何事情)?
解决:解决ping.它不会超过一两秒钟.
编辑2:更新了一些.这是最终的批处理文件:
- @echo off
- :top
- :: Loop through arp table entries and look for my Android device's MAC address
- for /f "tokens=1-5 skip=3" %%f in ('arp -a') do (if "%%g"=="xx-xx-xx-xx-xx-xx" set ip=%%f)
- if "%ip%"=="" (
- echo Discovering network...
- :: Ping all IPs from 192.168.0.1 to 254
- for /L %%N in (1,1,254) do start /b ping -n 1 -w 200 192.168.0.%%N >nul
- timeout 1 >nul
- goto :top
- ) else (
- echo Mapping network location to drive K
- net use k: http://%ip%:8080 /user:francis underwood /persistent:no
- if exist k: explorer k:
- :: Using FTP (please configure user and pass)
- :: explorer ftp://user:pass@%%f:6262
- )
- )
我试过这个并且它有效:
- for /L %N in (1,254) do start /b ping -n 1 -w 200 192.168.0.%N
如果手机启用了ICMP,您应该没有问题.