Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

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

Terminal - 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
2009-08-26 06:04:24
User: AlecSchueler
Functions: echo ping
-2
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, 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.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

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. :-)

Comment by Abiden 277 weeks and 2 days 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
Comment by 0x89 277 weeks and 2 days 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
Comment by DaveQB 277 weeks and 2 days ago

Rather

for i in 192.168.1.{61..71}; do ping -c 1 "$i" &> /dev/null && echo "$i" ;done
Comment by DaveQB 277 weeks and 2 days 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'.

Comment by Abiden 277 weeks and 2 days 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?

Comment by AlecSchueler 277 weeks and 1 day ago

@0x89

Yeah, I don't know how I forgot about &&. Silly mistake.

Comment by AlecSchueler 277 weeks and 1 day 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.

Comment by Abiden 277 weeks and 1 day ago

Your point of view

You must be signed in to comment.

Related sites and podcasts