![](/img/trans.png)
[英]how to get information of particular ip or hostname in linux shell scripting
[英]Get IP from hostname or FQDN using shell scripting
我想使用Shell脚本从主机名或FQDN中提取IP。 如果我使用主机名Ping,它将在输出中为我提供IP,但是如何从输出中提取IP以在Shell脚本中使用。
ip=`nslookup <fqdn> | grep -m2 Address | tail -n1 | cut -d : -f 2`
例如。
$ ip=`nslookup stackoverflow.com | grep -m2 Address | tail -n1 | cut -d : -f 2` && echo $ip
151.101.1.69
这对我有用:
IP1 = $(ping -c 1“ $ IP” | grep PING | awk -F'(''{print $ 2}'| awk -F')''{print $ 1}')&> / dev / null
IP为FQDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.