Working on a shell script that takes a machine name as an argument and then determines if the host is on the local network (same network as the machine that ran the script).
How can I get the IP address from the machine name? Once I get that I should be able to compare that IP with the local one to see if they’re on the same subnet.
You can use
nslookup(http://linux.die.net/man/1/nslookup),dig(http://linux.die.net/man/1/dig) orhost(http://linux.die.net/man/1/host) command-line utilities.For example, here is the result of running
hostfor getting A-records for stackoverflow.com from DNS server: