简体   繁体   中英

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 -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]

I've tried various incantations of sed with no luck. 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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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