![](/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.