Echo the local IP addresses of the machines on your local network

for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done
If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.

-2
2009-08-26 06:04:24

What Others Think

Check out nmap: nmap -sT -p 22 192.168.1.* Also if the host that is running ssh has a host name, you can just use the host name in the LAN. i.e. ssh user@hostname Thanks zeroconf. :-)
Abiden · 473 weeks and 1 day ago
@ AlecSchueler: uneccessary test (aka [): for i in 192.168.1.{61..71}; if ping -c 1 $i &> /dev/null; then echo $i;fi;done If you don't have nmap, you can try if the ssh port is open with nc: nc -w1 -z ciptux.physik.uni-bonn.de 22 @Abiden: To replicate what AlecSchueler did, your command should be: nmap -sT -p 22 192.168.1.61-71
0x89 · 473 weeks ago
@0x89 You missed a 'do' for i in 192.168.1.{61..71}; do if ping -c 1 $i &> /dev/null; then echo $i;fi;done Or for i in 192.168.1.{61..71}; do ping -c 1 "$i" &> /dev/null && then echo "$i" ;done
DaveQB · 473 weeks ago
Rather for i in 192.168.1.{61..71}; do ping -c 1 "$i" &> /dev/null && echo "$i" ;done
DaveQB · 473 weeks ago
@0x89 " Echo the local IP addresses of the machines on your local network If you need to ssh into a computer on the local network but you're unsure of the ip to use" The user is not sure what host is running ssh on it. So why not scan the whole range? I guess AlecSchueler may have to be a bit more specific. Maybe I put too much focus into, "you're unsure of the ip to use " Also "192.168.1.{61..71}", does not even work. Here's a solution if you do not have nmap but you have nc at hand. for i in $(seq 61 71); do nc -vv -z -w1 192.168.1.${i} 22; done Also: @0x89 For netcat to produce any output, you must specify at least one '-v'.
Abiden · 473 weeks ago
@Abiden Yes, this was intended for use when you didn't know the IP at all. 192.168.1.{61..71} works fine for me in bash 4.0.28 though. @0x89 What if you have neither nmap or nc installed?
AlecSchueler · 473 weeks ago
@0x89 Yeah, I don't know how I forgot about &&. Silly mistake.
AlecSchueler · 473 weeks ago
@Alec I was mistaken, about '192.168.1.{61..67}'. When I had tested it, I had used an additional '.', so that's why it didn't work for me. lol Also Alec, it seems that most distros are including netcat as of recently from my experience.
Abiden · 473 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: