Sponsored Content
Full Discussion: IP Ping Sweep
Top Forums Shell Programming and Scripting IP Ping Sweep Post 302902689 by sudo on Wednesday 21st of May 2014 05:29:49 PM
Old 05-21-2014
IP Ping Sweep

I put this together to search for unused IP addresses on a router. It's run as a Bash Command on OSX 10.9. Basically the user inputs the router address' IP range to sweep. 'jot' spits out a list of IP addresses based on that input and each one of those gets pinged. The output looks like this (tab delimitated):

xx.xxx.xx.xx Used name.domain.com
xx.xxx.xx.xx Used No Domain
xx.xxx.xx.xx Not_used


I was hoping to get help on 2 topics:

1. How can I manage error handling in the user input fields?
The first call to the user must only contain the first three quadrants of the router address: xx.xxx.xx(x). If I can just have it verify the input is numbers only with no more/less than 3 periods, that is sufficient
The last two calls are the low/high range inputs for the forth quadrant of the IP address which should be no more than 3 numbers (only numbers).

if entered incorrectly I would really like it to loop around and re-ask the user for that same input.

2. To exit, I press 'ctrl + c' but it requires I press it like 20 times before it breaks the actual process. I'm guessing I'm just breaking that instance of the while loop and it's moving onto the next line. Is there a more elegant way to do this without closing the window?

Any insight is appreciated. If there are any parts that can be streamlined below, let me know.

Code:
echo "\nEnter first three quadrants of router address (must contain three periods) \nExample- xx.xxx.xx. :"
read PT1ADD
echo 'Enter beginning range of the fourth quadrant :'
read PT2ADD
echo 'Enter the end range of the forth quadrant :'
read PT3ADD
echo '\n--------------------------------------'
echo 'Running scan on '$PT1ADD$PT2ADD-$PT3ADD
echo '--------------------------------------\n'
jot -w  $PT1ADD $PT3ADD $PT2ADD $PT3ADD | uniq |
while read SRC
do ping -c1 -W1 $SRC &>/dev/null
STATUS=$(echo $?)
    if [ $STATUS == 0 ]; then
        echo $SRC '\tUsed' | tr '\n' '\t'
        host $SRC | awk '/pointer/ {print $5}' | grep -m1 '.com' || echo 'No Domain'

## ^ I know grep is redundant here but if awk failed to find "pointer" it did not trigger the || echo 'No Domain' command. 
Grep was my workaround ##

    elif [ $STATUS == 2 ]; then
    echo $SRC '\tNOT_Used'
    else echo '\tPing Error Occured'
    fi
done
echo '\n--------------------------------------'
echo 'Scan Complete'
echo '--------------------------------------\n'


Last edited by sudo; 05-21-2014 at 06:30 PM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ping -t

I need a script that recieves an IP adress and a number of seconds as arguments. and display a massage if the IP replies or not. (8 Replies)
Discussion started by: jaber87
8 Replies

2. UNIX for Dummies Questions & Answers

Ping

Hi , I have one system installed on Linux Red Hat 3.0. I have ip of system 3.156.168.*** and i want to ping some port that is on this IP which command i can do this? sam70 (1 Reply)
Discussion started by: sam70
1 Replies

3. Linux

Not able to ping

Hi All, Need your help one more time. I am trying to ping a linux machine which is not responding to ping. However traceroute can reach the machine and I can log in to it by ssh. I have checked /proc/sys/net/ipv4/icmp_echo_ignore_all it is already set as "0". It is not happening in the... (1 Reply)
Discussion started by: ailnilanjan
1 Replies

4. IP Networking

Can't Ping

I have an old MP-Ras Unix system. I have setup netowkring but am unable to ping any local network pcs or the default gateway. If i use the arp -a command I receive the correct mac address for all connected pcs but I cannot ping anything except the local address. Any help would be appreciative. ... (7 Replies)
Discussion started by: Rutgerncas
7 Replies

5. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

6. IP Networking

PING

I am unable to ping my remote server.My server is unable to ping the same. both are able to ping the gateway. both the ip's are on same network.i use a proxy tunnel on my remote server.Help if any clues. (6 Replies)
Discussion started by: oslbhavana
6 Replies

7. UNIX for Dummies Questions & Answers

Where is PING ?

SHAME, that's all that I'm felling right now, however I'm not finding PING or either tracert in my box (Solaris 10). 1) Yes my PATH does have /usr/bin /usr/sbin # echo $PATH /opt/csw:/usr/bin:/sbin:/usr/sbin:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin:/opt/csw/gcc2/bin:/opt/csw/bin 2) If I... (1 Reply)
Discussion started by: pxb368@motorola
1 Replies

8. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

9. OS X (Apple)

A Bash Audio Sweep Generator...

This is a small program as a tester for a basic sweep generator for bandwidth testing of AudioScope.sh. This DEMO is only capable of 4KHz down to about 85Hz and back due to the low bit rate, but it is proof of concept for a much wider variant using a much higher bit rate. The file generated... (4 Replies)
Discussion started by: wisecracker
4 Replies

10. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 06:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy