简体   繁体   中英

get remote ip of address in a value for use in shell script

I am using a CentOS server, and i want to get a remote dynamic ip in a value to use in a script. Right now the script gets the ip like this:

    current_ip=$(curl --silent http://ipecho.net/plain)

but since i am moving the script to a server, i need it to ping my dyndns domain name and get my ip since its going to be changing every now and then. Is there a way to do this with ping or something ? So i can add in current_ip my ip every time the script executes ? -Thanks

To resolve a domain name, try the host utility:

$ host -t A stackoverflow.com
stackoverflow.com has address 198.252.206.140

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