简体   繁体   English

如何仅从nmap结果中获取IP地址

[英]How do I get ONLY the IP address from an nmap result

How do I strip out an IP address the resultant line from arp which includes the correct MAC address and the IP address the machine is found at with something like arp -a | grep "70:d1" > address_file.txt 如何从arp剥离IP地址,结果行包括正确的MAC地址和使用arp -a | grep "70:d1" > address_file.txt类的机器找到的IP地址arp -a | grep "70:d1" > address_file.txt arp -a | grep "70:d1" > address_file.txt

This gives me the following output: ? (10.0.0.9) at b8:27:eb:3:79:d1 on en0 ifscope [ethernet] 这给了我下面的输出: ? (10.0.0.9) at b8:27:eb:3:79:d1 on en0 ifscope [ethernet] ? (10.0.0.9) at b8:27:eb:3:79:d1 on en0 ifscope [ethernet]

I've tried various incantations of sed with no luck. 我已经尝试了sed的各种咒语,但是没有运气。 The latest attempt is: 最近的尝试是:

cat address_file.txt | sed 's/(\d{1,3}\.){3}\d{1,3}//p' address_file.txt

There is probably something procedurally wrong that I'm doing, but I'm running low on patience as this was supposed to be a quick and dirty hack to provide some automation. 我可能在程序上做错了一些事情,但是我的耐心不高,因为这本来是提供一些自动化的快速又肮脏的技巧。 I would also note that I am using a Mac running OS Mojave as I have read that they are some regex differences between BSD sed and other versions of sed. 我还要指出的是,我使用的是运行OS Mojave的Mac,因为我读到它们是BSD sed与其他版本sed之间的一些正则表达式差异。

I should note that I perform a nmap of the subnet because the arp entry can be stale and the machine will no longer be online or a different address but has produced no traffic. 我应该注意,我执行了子网的nmap,因为arp条目可能已过期,并且该计算机将不再处于联机状态或其他地址,但没有产生任何流量。

使用括号提取其中的内容:

arp -a | sed -e s'/.*(\(.*\)).*/\1/g'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM