我试图制作一个脚本,该脚本将提供连接到我的网络的设备。 My last question是用硒查找元素的问题,但我发现了另一种获取元素的方法。 现在,我获得了连接到我的wifi网络的所有设备的详细信息的完整字符串。看起来像这样:
@ @ pc/devicename1/ConnectedProtocol (usually 802.11)/Device mac address/DHCP/local ip adress/a random number that i don't want to use /another number that i don't want to use/ipv6 address/:ipv6::|pc/devicename1/ConnectedProtocol (usually 802.11)/Device mac address/DHCP/local ip adress/a random number that i don't want to use/another number that i don't want to use/ipv6 address/:ipv6 address::|@ 0@ 0|0|0|0@ 1@
因此,正常的设备列表如下所示:
@ @pc/android-d45cb2db4c2da/802.11/12:34:56:78:90:ab/DHCP/192.168.1.2/2/1/fe60::84c5:6de3:fe65:6bd8/:84c5:6de3:fe65:6bd8/::|pc/android-cd4b56add5/802.11/12:34:56:78:90:ab/DHCP/192.168.1.3/2/35/fe60::1547:bbb:fe69:8441/:2605:fff:fe97:9145/::@ 0@ 1|0|0|0@ 1@
输出应如下所示:
然后是另一个设备。 我该怎么办?
答案 0 :(得分:0)
您可以将初始字符串拆分为包含每个设备信息的较小子字符串,然后再次拆分以获取所需信息:
devices = "@ @pc/android-d45cb2db4c2da/802.11/12:34:56:78:90:ab/DHCP/192.168.1.2/2/1/fe60::84c5:6de3:fe65:6bd8/:84c5:6de3:fe65:6bd8/::|pc/android-cd4b56add5/802.11/12:34:56:78:90:ab/DHCP/192.168.1.3/2/35/fe60::1547:bbb:fe69:8441/:2605:fff:fe97:9145/::@ 0@ 1|0|0|0@ 1"
devices = devices.split("::|")
for device in devices:
device = device.split("/")
print("Device name: " + device[1])
print("MAC address: " + device[3])
print("Local IP: " + device[5])
print("Connected protocol: " + device[2])
print()
输出:
Device name: android-d45cb2db4c2da
MAC address: 12:34:56:78:90:ab
Local IP: 192.168.1.2
Connected protocol: 802.11
Device name: android-cd4b56add5
MAC address: 12:34:56:78:90:ab
Local IP: 192.168.1.3
Connected protocol: 802.11
注意:为了确定您使用的是WLAN还是以太网协议,还是其他协议,最好创建一个带有IEEE命名标准(例如802.11
)键的字典,并对协议的类型进行评估。 WLAN
。