citizenen
citizenen

Reputation: 703

(ba)sh - Determine (based on machine name) whether a computer is on the local network

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.

Upvotes: 1

Views: 513

Answers (2)

anishsane
anishsane

Reputation: 20980

What do you mean by local network? subnet or (windows) domain or within LAN?

You may also have a look at traceroute utility.

Upvotes: 0

werupokz
werupokz

Reputation: 796

You can use nslookup (http://linux.die.net/man/1/nslookup), dig (http://linux.die.net/man/1/dig) or host (http://linux.die.net/man/1/host) command-line utilities.

For example, here is the result of running host for getting A-records for stackoverflow.com from DNS server:

$ host -tA stackoverflow.com
stackoverflow.com has address 69.59.197.21

Upvotes: 2

Related Questions