我有一个命令可以扫描网络上的设备,然后提供很多关于它们的信息,包括它的 ip 地址,如何隔离 ip 并将其转换为字符串?知道它扫描特定设备,像 nmap 这样的东西对我的情况不起作用,另外,会有多个 IP,如何将它们隔离在不同的字符串中?
输出 :
[{'ip': u'xxx.xxx.xx.xx',
'port': xxxxx,
'capabilities': {
u'hue': u'0',
u'color_mode': u'2',
u'name': u'xxxxxx',
u'power': u'on',
u'support': u'get_prop set_default set_power toggle set_bright start_cf stop_cf set_scene cron_add cron_get cron_del set_ct_abx set_rgb set_hsv set_adjust set_music set_name',
u'rgb': u'16712469',
u'fw_ver': u'44',
u'bright': u'100',
u'model': u'stripe',
u'ct': u'2000',
u'id': u'0x0000000005e1c8db',
u'sat': u'100'
}
}]
如果您收到可解析的输出,只需执行以下操作:
ips= []
for data in output:
ips.append(data["ip"])
或者作为评论建议:
ips = [data["ip"] for data in output]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句