Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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
add comment

2 Answers

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
add comment
#!/bin/bash
echo Please enter host you would like to ping:
read PING
ping "$PING"
share|improve this answer
1  
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: ehow.com/how_5088467_determine-two-ips-same-subnet.html So, i write shell script follow this guide. Anything else more simple? –  duongvanthai Nov 28 '12 at 3:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.