Network probe script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Network probe script
# 1  
Old 05-21-2010
Network probe script

Hi. I just wrote my first shell script, it's very ugly but it works. I was wondering if someone could help me clean it up a bit.

Original Problem: Current command-line tool (FIND-NEIGHBORS.exe) outputs MAC addresses of neighboring wireless devices and I need the IP address instead; fortunately our current IP scheme assigns the LAST TWO hexadecimal values of the MAC address as the MIDDLE two octets in the IPv4 address. All devices are on the 10.0.0.0 subnet and all wireless interfaces end with a 1 in their last octet. (i.e. A device with the MAC address - 00:05:12:0A:A6:08 would have the IP address 10.166.8.1) Here's the code:

#! /bin/bash
## Read user input and execute FIND-NEIGHBORS command to query the specified device. It takes a few seconds for the FIND-NEIGHBORS tool to return its output.
echo -e "ENTER IP ADDRESS: \c "
read IPADDRESS; FIND-NEIGHBORS.exe $IPADDRESS > INPUT.TXT ; sleep 5 ;

Here's the output from the FIND-NEIGHBORS command,INPUT.txt:

MAC SIG RATE
00:05:12:0A:A6:08 -83 1.5
00:05:12:0A:8F:2F -64 6.0
00:05:12:0A:A1:6A -46 6.0
00:05:12:0A:A5:8D -58 1.5
00:05:12:0A:A4:9A -64 1.5
00:05:12:0A:A2:9B -54 1.5
00:05:12:0A:AB:A4 -36 6.0
00:05:12:0A:87:C8 -37 6.0

This part uses the grep command to parse out the last two hexadecimal values in each MAC address from INPUT.txt and output them to TEMP1.txt and TEMP2.txt

TEMP1.txt contains the FIRST of the LAST TWO hexadecimal values, (ie. A6) TEMP2.txt contains the SECOND of the LAST TWO hexadecimal values, (ie. 08)

cat INPUT.txt | grep 00 | cut -d ":" -f5 > TEMP1.txt ;
cat INPUT.txt | grep 00 | cut -d ":" -f6 | cut -d "-" -f1 | cut -d ":" -f1 > TEMP2.txt ;

## The next two commands convert the hexadecimal values into decimal values and outputs them to TEMP3 and TEMP4 respectively

cat TEMP1.txt | while read value; do printf "%d\n" 0x$value; done > TEMP3.txt ; cat TEMP2.txt | while read value; do printf "%d\n" 0x$value; done > TEMP4.txt ;

## This command combines TEMP3.txt and TEMP4.txt into one file and appends the appropriate numbers to make it an IPv4 address.
paste TEMP3.txt TEMP4.txt | awk '{print "10."$1"."$2".1"}' >> TEMP5.txt ;

TEMP5.TXT
10.166.8.1
10.143.47.1
10.161.106.1
10.165.141.1
10.164.154.1
10.162.155.1
10.171.164.1
10.135.200.1

After the IP addresses are written to the TEMP5.txt this data is then used as an input to scan for more devices on the network.

cat TEMP5.txt | while read line ; do FIND-NEIGHBORS.exe $line > INPUT.txt ; sleep 5 ;
cat INPUT.txt | grep 00 | cut -d ":" -f5 > TEMP1.txt ; sleep 5 ; cat INPUT.txt | grep 00 | cut -d ":" -f6 | cut -d "-" -f1 | cut -d ":" -f1 > TEMP2.txt ;

cat TEMP1.txt | while read value; do printf "%d\n" 0x$value; done > TEMP3.txt ; cat TEMP2.txt | while read value; do printf "%d\n" 0x$value; done > TEMP4.txt ;
paste TEMP3.txt TEMP4.txt | awk '{print "10."$1"."$2".1"}' >> TEMP5.txt ; sleep 5 ; done

Alright, that's the bulk of it. I hope this isn't too confusing and it gives you a general idea of what I am trying to accomplish. Any help with this would be greatly appreciated.

Last edited by skeller; 05-21-2010 at 11:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Help Explain the output of probe-scsi

Can anyone explain the output of probe-scsi command below? ok probe-scsi Target 0 Unit 0 Disk SEAGATE ST373207LSUN72G 045A Target 1 Unit 0 Disk SEAGATE ST373207LSUN72G 045A I have no idea what it means. I tried to read online but I still did not understand. I appreciate... (6 Replies)
Discussion started by: cjashu
6 Replies

2. Solaris

probe-scsi-all hangs - not returning anything

HI I have a V240 server and the probe-scsi-all on the Ok prompt is taking forever. I have tried powercycling the server multiple times. also tried set-defaults and reset-all.. COuld anyone tell the solution to this.. I have run out of options now. Following is the only thing... (8 Replies)
Discussion started by: ningy
8 Replies

3. Shell Programming and Scripting

Network probe script

Hi. I just wrote my first shell script, it’s very ugly but it works. I was wondering if someone could help me clean it up a bit. Original Problem: Current command-line tool (FIND-NEIGHBORS.exe) outputs MAC addresses of neighboring wireless devices. I need the IP address instead;... (0 Replies)
Discussion started by: skeller
0 Replies

4. High Performance Computing

What does the 'probe' do in VCS?

Weird question I know, but I'm intrigued. Say for instance you have an Application in an SG with the usual start/stop/monitor. To successfully probe does it just check for existence of the script/file ? Thanks... (1 Reply)
Discussion started by: itsupplies
1 Replies

5. BSD

PROBE not find the device ID

Hi All, Probe is not returning the Device ID, while device (PCI Express-to-PCI Bridge) is already detected by "lspci". I checked this with printing all the device ID which has been detected. Can anyone give me any suggestion or solution. Thanks (in advance) Appu (2 Replies)
Discussion started by: appu
2 Replies

6. Solaris

probe-scsi => error

i have a new netra 240 server when i make probe-scsi in obp i have this output : ERROR: /pci@1c,600000: Last Trap: Fast Data Access MMU Miss am upgarading obp firmware but the problem is always here the os solaris 10) is installed correctely and i can use it , when i type #format i can see... (2 Replies)
Discussion started by: lid-j-one
2 Replies

7. Solaris

Help probe-scsi-all

I have run init 0 to bring it to OK prompt. I know that probe-scsi-all can hang the system. I want to know what is the difference between probe-scsi-all and probe-scsi. I was told that probe-scsi-all external and internal devices and probe-scsi shows only internal devices. what dose this ... (3 Replies)
Discussion started by: nitinkgoud
3 Replies

8. Solaris

solaris booting to probe menu

Hi all, everytime the sun fire server reboots in always boots to the probe menu. This needs to be manually booted by command named boot. Is there a boot file somewhere on the system that changes the boot script to boot fully not to the probe menu. (2 Replies)
Discussion started by: dennisca
2 Replies

9. Programming

PCI device probe and find

:confused: Hi, everybody. Pleeeeese HLP!!! I write PCI device driver for bridge controller PCI-VME bus in freeBSD 2.2. And firs run function probe(): static char* probe(tag, type). Whuy probe() don't work for my vendorID and deviceID (bridge controller and videoadapter). But... (1 Reply)
Discussion started by: Alex_T
1 Replies

10. UNIX for Dummies Questions & Answers

probe software

can anyone point me towards a program to list what's installed on my sunOS box and their version numbers. (2 Replies)
Discussion started by: sphiengollie
2 Replies
Login or Register to Ask a Question