Help with ip search script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with ip search script
# 1  
Old 07-26-2011
Java Help with ip search script

Hi

Obviously first time poster here. I have been set the task of creating a network diagram for each of our clients in the business i work for. After identifying ip adresses of firewalls name servers and the like im got to the point where i found it impracticle to go through 254 ip address and check for a responce. (Im doing this work remotley through a VPN/Putty combination)

As im new to scripting (Only started about a week ago) im not sure on much of the basics so have been making my way through man pages and google sites all week Smilie

So my question. So far, my code is as follows:

Code:
#!/bin/bash
#Author: John Crombie
#Small script to ping all ip's within a range specified and to write to file all ips that return a responce.


echo Debugging!

echo xxx.xxx.xxx.x Successfull Pings:>/home/johnc/Scripts/inprogress/ipSearch/ping.log

#for i in {1..254}
for i in {1..5}
do
        ping -c 1 xxx.xxx.xxx.$i>>/home/johnc/Scripts/inprogress/ipSearch/ping.log
done

(Replace xxx with correct IP naturally)

Now the problem. While it does what i want the log files is a little clumsy to go through so i want to do the following:

1. send all ip address with no responce to ping to /dev/null
2. go from the sample output below to just the ip address of the successfull ping attempts.

EXAMPLE:
Before:
PING xxx.xxx.xxx.253 (xxx.xxx.xxx.253) 56(84) bytes of data.

--- xxx.xxx.xxx.253 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

PING xxx.xxx.xxx.254 (xxx.xxx.xxx.254) 56(84) bytes of data.
64 bytes from xxx.xxx.xxx.254: icmp_seq=1 ttl=63 time=33.3 ms

--- xxx.xxx.xxx.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 33.368/33.368/33.368/0.000 ms

After:
xxx.xxx.xxx.254

So the thoughts i had on this was that i need to firstly add some additional constraints on the ping command and then to pipe the ping.log file through a grep comman of some kind and finishing of with some sort of restrictive redirection on the results of grep....

But i would really value some input.

Let me know if i can provide anymore info or this inst clear. Or its in the wrong forum?

Regards,
John.
# 2  
Old 07-26-2011
Code:
 
for i in {1..5}
do
 logFile="/home/johnc/Scripts/inprogress/ipSearch/ping.log"
 ping -c 5 -w 5 -n xxx.xxx.xxx.$i | grep -q "bytes from" && echo "$i" >> $logFile || echo "$i not Reachable"
done

# 3  
Old 07-26-2011
Without grep:
Code:
logFileOk="/home/johnc/Scripts/inprogress/ipSearch/ping.log"
logFileNOk="/home/johnc/Scripts/inprogress/ipSearch/ping_err.log"
for octet in {1..254}
do
    ping -c 1 -W 1 -q -n xxx.xxx.xxx.$octet >/dev/null 2>&1 && echo "$octet" >> $logFileOk || echo "$octet" >> $logFileNOk
done

# 4  
Old 07-26-2011
Thanks to both responces.

I went with the first purely due to the fact that it was there first so i went of and played with it for a while before coming back online.

@pludi: may i ask what octet is for?

this is what i ended up with:

Code:
#!/bin/bash
#Author: John Crombie
#Small script to search single network for attached computers

echo "Enter the ip address base: (eg: 100.10.1.)"
echo -n "Address: "
read ipBase

for i in {1..254}
do
        successLogFile="/home/johnc/Scripts/working/NetworkSearch/pingSuccess.log"
        failLogFile="/home/johnc/Scripts/working/NetworkSearch/pingFail.log"

        ping -c 5 -w 5 -n $ipBase$i | grep -q "bytes from" && echo "$ipBase$i" >> $successLogFile || echo "$ipBase$i not Reachable" >> $failLogFile
done

If you can think of things i might add to make it more efficient please dont hesitate to ask.

Regards,
John Crombie
# 5  
Old 07-26-2011
octet in my example is just a variable name (like ipBase or i in your script), and named thus because the "parts" of an IP address are usually called "octets".
# 6  
Old 07-26-2011
Thanks

I ment why octet, what did it signify, as opposed to what is it for like i asked so thanks for answering what i ment to ask but didnt...Smilie

And Octet huh? Due to the number of bits each "part" is made of? Or some other reason?
# 7  
Old 07-26-2011
Because a Byte isn't necessarily 8 bits, but the number of bits used by a system to encode a character. Usually that's 8 bits, but in places where it's defined that 8 bits are needed the word Octet is usually used.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Timebased search script

Hi there first of all, sry for my bad english and possible mistakes .-) I write scripts for my server to get my live easier. So my next one will be a script, where I can find special files in a folder. I put with a script of mine files in a folder on the server with following name... (5 Replies)
Discussion started by: bigsanch
5 Replies

2. Shell Programming and Scripting

Please help in creating search script

Hi all, Hope everyone is doing fine. I need a help in creating search script. I have file which contains job names and job recs. I need to select specific job name and next line which is job rec job (BLREEXTT) { Record B${cycle}${month}${year}000075; follows BLCYRRTCHKT; ... (5 Replies)
Discussion started by: taksistalo
5 Replies

3. Shell Programming and Scripting

Search and Copy Script

Dear All, I would like to create a Unix script which basically searches for files which are more than 2 days old and copy only the new files to the destination. What i mean is if the destination may have most of the files, it may not have only last 2 to 3 days file. I am able to create the... (6 Replies)
Discussion started by: rrb2009
6 Replies

4. Shell Programming and Scripting

Log Search Script

Hi, I am trying to write a script to search a log- IPaddress being the search criteria, I would ideally like the script to ask the ipaddress Enter IP address - 244.258.27.225 And the ideal result would be for the script to get all the entries in the log file for a particular IP address,... (3 Replies)
Discussion started by: fuzion.hyd
3 Replies

5. Shell Programming and Scripting

Small Search script

I need to write a small shell script which does the following : I have a file : root/var/log/ocmp/ocmpclient.log This is a log file which is continuosly getting updated . I have to keep looking into this file all the time. I have to look for four keywords, "File Detected", File Sending",... (2 Replies)
Discussion started by: appu1987
2 Replies

6. Shell Programming and Scripting

script to search a file

hi all i have a requirement to write a script which will serach a file in a particuar location for 3 hours from the time when the script is run.if during this period the file arrives in a particular location then this will transmit the file to a other server.please help me writing the script which... (1 Reply)
Discussion started by: dr46014
1 Replies

7. UNIX for Advanced & Expert Users

Help with search script

HI all, I am trying to find files that have .cc3 file extenstion folder using this script below, but this fails as there are files in the folder and i get a message saying i have no files. Please anyone reveiw and let me know if i am missing anything.I am working on this from two days and i... (9 Replies)
Discussion started by: bsandeep_80
9 Replies

8. Shell Programming and Scripting

Search File Script

Nice forum for noobs like me to UNIX. With that said, I need assistance. I am trying to make a script to search files for a specific date and string within the file. Then I need the script to move the file that have the specific date and string to a directory. In the interim I have been manually... (7 Replies)
Discussion started by: I4ce
7 Replies

9. Shell Programming and Scripting

Search script

I need to create a script called 'find_data' that will search a file by passing two parameters to it :confused: . I'm pretty good with scripting but haven't really gotten into sed and awk that much (and no perl whatsoever). I'm really at a loss and need to get something working in the next... (14 Replies)
Discussion started by: BCarlson
14 Replies

10. Shell Programming and Scripting

script to search all the directories

Hi there, Is there any command or script to search all the directories for duplicated files? Thanks, Abrahim (3 Replies)
Discussion started by: abk
3 Replies
Login or Register to Ask a Question