Can i see wich Computers are up in my network with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can i see wich Computers are up in my network with a script
# 1  
Old 05-20-2015
Tools Can i see wich Computers are up in my network with a script

Code:
#!/bin/bash

for ((n=0 ; n < 254 ; n+=1))
do
    ip=192.168.0.$n
    if ping -c 1 -w 1 $ip > /dev/null 2> /dev/null >> /etc/logping.txt; then  
        echo "${ip} is up" # output up
        # sintax >> /etc/logping.txt log with .txt format
    else
        echo "${ip} is down" # output down
    fi
done

This is code that I already have when i run the script ./testping.sh 220
than i gave this out put
Code:
192.168.0.0 is down
192.168.0.1 is up
192.168.....
...
.
.
.
.
192.168.0.220

Now I want to limit the output to two lines but it doesn't work

I want to also implement 2 arguments to this script
the argument xx-yy en -t
xx-yy a range of IP address when I give the parameter ./testping.sh 67-80 it scans the range between this IP addresses

-t counts the IP address with 200 for example, when I run the script with the parameter -t, ./testping.sh -t 17, then I want as output 192.168.0.217

Last edited by Don Cragun; 05-21-2015 at 02:36 PM.. Reason: Added another ICODE tag set.
# 2  
Old 05-20-2015
I think that this is what you want;

Code:
#!/bin/bash

for ((n = ${1} ; n < ${2} ; n+=1))
do
    ip=192.168.1.$n
    if ping -c 1 -w 1 ${ip} > /dev/null 2> /dev/null >> /etc/logping.txt; then  
        echo "${ip} is up" # output up
        # sintax >> /etc/logping.txt log with .txt format
    else
        echo "${ip} is down" # output down
    fi
done

To run the script do as follows;

Code:
[root@ekbit13 bin]# ./testping.sh 10 20
192.168.1.10 is down
192.168.1.11 is down
192.168.1.12 is up
192.168.1.13 is down
192.168.1.14 is down
192.168.1.15 is down
192.168.1.16 is down
192.168.1.17 is down
192.168.1.18 is up
192.168.1.19 is down
[root@ekbit13 bin]#

The range is dependent on the two numbers that you provide after the script name, so for example;

Code:
[root@ekbit13 bin]# ./testping.sh 1 20
192.168.1.1 is up
192.168.1.2 is down
192.168.1.3 is down
192.168.1.4 is down
192.168.1.5 is down
192.168.1.6 is down
192.168.1.7 is down
192.168.1.8 is down
192.168.1.9 is down
192.168.1.10 is down
192.168.1.11 is down
192.168.1.12 is up
192.168.1.13 is down
192.168.1.14 is down
192.168.1.15 is down
192.168.1.16 is down
192.168.1.17 is down
192.168.1.18 is up
192.168.1.19 is down
[root@ekbit13 bin]#

Will ping from 1 to 20, as to adding switches as in your request for a "-t" which increments the IP address by 200 - you'll need to specify if it's output that you want changed or the actual address that is pinged.

Of course you could just use something like Xymon or Nagios and have it monitored all the time and automatically.

Regards

Gull

Last edited by gull04; 05-20-2015 at 04:44 PM.. Reason: Incomplete info
# 3  
Old 05-20-2015
Any specific reason the other 2 scripts in that other thread (Problems with past arguments in script) dont work / suffice?
Incl a third thread.

Last edited by sea; 05-21-2015 at 07:44 AM..
This User Gave Thanks to sea For This Post:
# 4  
Old 05-21-2015
Hi Folks,

Sorry about this, I didn't realise that this had already been done to death.

Regards

Gull
# 5  
Old 05-21-2015
Quote:
Originally Posted by Roggy
Code:
#!/bin/bash

for ((n=0 ; n < 254 ; n+=1))
do
    ip=192.168.0.$n
    if ping -c 1 -w 1 $ip > /dev/null 2> /dev/null >> /etc/logping.txt; then  
        echo "${ip} is up" # output up
        # sintax >> /etc/logping.txt log with .txt format
    else
        echo "${ip} is down" # output down
    fi
done

This is code that I already have when i run the script ./testping.sh 220
than i gave this out put
Code:
192.168.0.0 is down
192.168.0.1 is up
192.168.....
...
.
.
.
.
192.168.0.220

NO, it does not! That code doesn't look at any command line arguments and always prints ping results for IP addresses 192.168.0.0 through 192.168.0.254.
Quote:
Originally Posted by Roggy

Now I want to limit the output to two lines but it doesn't work
Huh?
What two lines of output do you want to get from asking for the status of IPE address 192.168.0.220?
Quote:
Originally Posted by Roggy

I want to also implement 2 arguments to this script
the argument xx-yy en -t
xx-yy a range of IP address when I give the parameter ./testping.sh 67-80 it scans the range between this IP addresses

-t counts the IP address with 200 for example, when I run the script with the parameter -t, ./testping.sh -t 17, then I want as output 192.168.0.217
Why do you keeping asking the same question? Doesn't the code I provided in post #5 in your previous thread do exactly this?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Fedora

Script for shutting down 48 computers

Hi All, I am pretty new to unix type languages. At work we have a server room with about 50 windows computers in one system and 50 in a unix system. We sometimes have power outages and I don't like the power slam. I wrote a windows batch file using sysinternals help to shutdown the windows... (4 Replies)
Discussion started by: Jeff Rollins
4 Replies

2. Red Hat

How do I network a Suse installed machine with other computers, specifically Red hat Linux?

How do I network a Suse installed machine with other computers, specifically Red hat Linux? This is for a school project, and I can't find any pages that tell how to network a Suse to other computers except how to use a printer. (1 Reply)
Discussion started by: Anna Hussie
1 Replies

3. Shell Programming and Scripting

Shell script to Shutdown Computers on Cluster

Hello all. I have built a cluster of 9 Macs for computational chemistry and I need a shell script that I can use from one computer to all the rest to shutdown. I have modified all of the Macs so that there is pass-wordless ssh. As well, I have modified each "visudo" file on each machine by... (1 Reply)
Discussion started by: marcozd
1 Replies

4. HP-UX

CSA wich exam?

Hello, I'm looking books and information for CSA certificate but in HP website, appears the right exam is HP0-091 but I found a book in amazon about HP0-A01 (includes 11.31?)exam, I think this is the last exam but it's extrange the HP website are obsolete. Anyone known wich is the right exam... (4 Replies)
Discussion started by: RuBiCK
4 Replies

5. Programming

read a file wich fscanf() in a function

I use fopen, fscanf, fclose to read a file. It can work well. since many files should be read, a function is created with the same code. But in the function, fscanf can not work well. for example, the first line of the the file is: > filename but the fscanf will give: 207/23/eee/34 it appears... (2 Replies)
Discussion started by: cdbug
2 Replies

6. UNIX for Dummies Questions & Answers

So if I was to use a unix based o/s as my first wich should it be?

I have never used any unix based operating systems and I am interested in trying. Wich would you prefer for me to use? Also I am looking to learn unix code not to use for anything else. (3 Replies)
Discussion started by: Slaviko
3 Replies

7. Shell Programming and Scripting

Script to get IP addresses of LAN computers

I need a shell script for OS X, one that can find IP addresses of machines connected to my LAN, get the names of the computer associated with those addresses, then display them like so in a list: "Bob's L33T Boxx: #.#.#.#" Something like the network scanner in Apple Remote Desktop is what I'm... (1 Reply)
Discussion started by: sladuuch
1 Replies

8. UNIX for Advanced & Expert Users

Is Unix a Network operating system for Macintosh computers

I am in the process of reading up on and learning about linux,and as i read, i am seeing that it was built off of the unix system platform,and i also believe that it is used in the mac computer field,i would like to know if this is true, and if i should learn about the macintosh computer... (2 Replies)
Discussion started by: Bill1263
2 Replies

9. Windows & DOS: Issues & Discussions

Wich one is beter Linux or Windows

I have no idea wich one. Ive always been a huge windows fan and well latly i've heard of Unix and Linux. Also, my friend wants to get Linux on his notebook and windows on his pc, the notebook being the master.(I think my friend is rather stupid wanting the notebook to be the master, but i've been... (3 Replies)
Discussion started by: Radionstorm
3 Replies
Login or Register to Ask a Question