Simple bashscript to see online LAN-sations

Newbie here, using openSUSE 11.3 KDE

Can anyone help me write a simple script that shows me which pc’s in a LAN are currently online. It would be nice to see in real-time pc’s go online or offline, visible on my desktop…

I would appreciate you help.
Thanks in advance

#!/bin/bash

NETWORK="10.0.0."

typeset -i I=1

while (( I < 255 ))
do      ping -c 1 ${NETWORK}${I} >/dev/null && echo "${NETWORK}${I} is alive"
        (( I += 1 ))
done

There are a few parameters to be changed by you. This will ping to all addresses in the 10.0.0.0/24 network. Thus change the 10.0.0. in yours (mind the . at the end).
It starts at 10.0.0.1, change to I=n for starting at 10.0.0.n.
It ends at 10.0.0.254, change to I < m for stopping at 10.0.0.m-1.

It will take time because all the “dead” addresses must time out before the next address is tested. Read the man page of ping.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sudo zypper in nmap #in case nmap is not already installed

nmap -sP 192.168.1.1-254

Good luck.

On 09/08/2010 11:06 AM, ritslinux wrote:
>
> Newbie here, using openSUSE 11.3 KDE
>
> Can anyone help me write a simple script that shows me which pc’s in a
> LAN are currently online. It would be nice to see in real-time pc’s go
> online or offline, visible on my desktop…
>
> I would appreciate you help.
> Thanks in advance
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJMh8TnAAoJEF+XTK08PnB5bUcQAMfYdmL+BZgsS7j0kV3LfQ3E
8a4v+h+ccUIWYfguq4z1W28KfaE9GCPhiWSm9ZEOLswVuiGowDCYqhGUQhcsUsaj
nLZnpxIAnph3Wghg6TGWtRcGjCrf9VyWrTJOUkqQM6nDvH0KL7VLO+mk2o1Z730p
BrIh2kD0HuMPsCoLooyncitujVZugodP1pI7CAjsCWWr1woymAut5T3vz++SDhkv
9+UwD8reRbvasZw0gNFCY2kQyxzp5VJCUJ1gxk+108zBhjl0HKAEJn7VTVn/1rH/
vNQfS+3fwslj1thE5vGOfIko7vAB95U7+pJH9JPwnR7//syeefS64k/2vzjSq0n1
h2vpX/Y7ghe09bjWkoJEocxLuK991/+oyxLHww8+aMlmvf/v5O8WxUNpGi+gSuTF
jpFT9fxTA+rEFBDr7sW6Hbjno/n71grAtWVlvo1xFgEEX8onwJntst43uDYucqIR
DIS6svZUnzsIVI5yhAw0zw1Wsc6xhZabq2ocJBm/Z8GJk9qHmc9Gix7uHn6hcjn/
10eHvoYKXI/skqS5bbZqlIAi7nh5UnRoxYPcfp5hlzgp9axsHwAk5xMK/q1I1nYG
wRUWqGn5OYCedywxnATx7iwS69tPmewk9H/wjX18kIpH9LB0fcOR+krQIySqvwtH
/qG8RxRzs1KCQZB3lamh
=W/ZH
-----END PGP SIGNATURE-----

That’s useful what Henk van Velden writes… now all ip’s are static (about 10 pc’s) so I just can code them in the script. This would make it easier I think.

Maybe ab@novell.com’s suggestion is also worthwhile to look at, though it may be it more sophisticated then you need. In any case there is a website about it inclusing it’s man page, to look at before installing: Nmap - Free Security Scanner For Network Exploration & Security Audits..

In case you go for a variant of my srcript, you can indeed use e.g.* I=120* as start end* I < 140* if they are in such sort of range range. Will spare a lot of time. I guess you can make those small changes yourself.

There’s also zenmap as a graphical frontend to nmap. You could also take a look at software.opensuse.org: Search Results, open the user home dirs from the search options, and see if there’s some program there for you.

ritslinux wrote:

>
> Newbie here, using openSUSE 11.3 KDE
>
> Can anyone help me write a simple script that shows me which pc’s in a
> LAN are currently online. It would be nice to see in real-time pc’s go
> online or offline, visible on my desktop…
>
> I would appreciate you help.
> Thanks in advance
>
>

Well… if all are Windows and/or if all have Samba, then you can run
nbtscan. It’s a lightning fast way to see what is out there.

Of course, again, you’d have to run it over and over to see things
“real time” (which of course, isn’t really, real time). A possible
alternative is to do snmp monitoring of the network switch, etc.

google for nbtscan (recommended)… runs great on Linux.