Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a Bourne shell script that takes a machine name as an argument and displays a message informing you whether the host is on the local network

share|improve this question

migrated from Nov 27 '12 at 9:25

This question came from our site for professional and enthusiast programmers.

how to know ip address from computername? Then compare with my ip to know is the same local network or not? – duongvanthai Nov 27 '12 at 4:39
We aren't going to do this for you. What have you tried? Are there any linux commands that can tell you this information? Where would machine names be stored on a Linux machine? – Codeguy007 Nov 27 '12 at 4:39
I'm beginer in unix system and i try alot of command to do this (4h search in google). But i can't get the information i want. – duongvanthai Nov 27 '12 at 4:44

ping -c 1 -t 5 a_machine_name >> /dev/null && echo "The machine is on LAN" || echo "The machine is not conencted to LAN"

share|improve this answer
echo Please enter host you would like to ping:
read PING
ping "$PING"
share|improve this answer
That doesn't tell him if it's on the local network though other than he should be able to figure that out from the IP. – Codeguy007 Nov 27 '12 at 5:18
traceroute -m 1 "$PING" I believe will tell you if the IP is on the same subnet. – Codeguy007 Nov 27 '12 at 5:27
@Codeguy: I find link help to determine two ips same subnet: So, i write shell script follow this guide. Anything else more simple? – duongvanthai Nov 28 '12 at 3:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .