473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Extract and compile a list of IP addresses after doing a system call of traceroute

12
Hi All - chasing down a means to initiate a traceroute, record results, and extract IP addresses in an (array?)

Here's what I'm thinking about so far, wonder if anyone's been down this road before and can offer advice if I'm going the right direction or not.

untested - pending permissions to initiate traceroute from server
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl -w
  3. use strict;
  4. use warnings;
  5. use CGI qw(:standard);
  6.  
  7. # assign a variable name to the CGI form value of the IP address
  8. my $IP = param('csrip');
  9.  
  10. # only proceed if the user inputs a value that exceeds 6 characters
  11. # as they may not know the IP address and we want to ignore if left blank
  12.  
  13. if ($IP = .{6,}) {
  14. # do a system call to execute the traceroute command? 
  15. # assign the stderr and stdout response to a variable
  16. my $trace = `tracert $IP 2>&1`;
  17. }
  18.  
  19. # should I try to extract the IP addresses from the long string of stderr & stdout using a find/replace?
  20. # or something else?
  21.  
  22. (my $iponly = $trace) =~ s/xxxxxxxxxx;
  23.  
  24. # assuming the path of substitution is successful
  25. # convert the new $iponly variable to an array
  26.  
  27. my @IPLIST= split(/,/,$iponly);
  28.  
  29. # then extract the IPs as needed 
  30.  
  31. print "the path is $IPLIST[1], $IPLIST[2]
  32.  
  33.  
Regards,
Hutch
Apr 18 '08 #1
2 2310
eWish
971 Expert 512MB
I have not had the need to do any trace route stuff. Have you looked into using Net::Traceroute might make it easier.

The next line of code won't return anything useful, since you are declaring it in your if statement block. Therefore, it goes out of scope when you try to access it again. Use strict will catch this for you.

Expand|Select|Wrap|Line Numbers
  1. my $trace = `tracert $IP 2>&1`;
This next line does not do anything either.
Expand|Select|Wrap|Line Numbers
  1. if ($IP = .{6,}) 
If you want to check for the $ip variable for at least six alpha numeric characters then you will need something like this.
Expand|Select|Wrap|Line Numbers
  1. if ($IP =~ / \w{6}/)
--Kevin
Apr 18 '08 #2
hutch75
12
Thanks for the Response Kevin,

The Unix Sys Admin showed me the error of my ways. I thought I couldn't run traceroute from the command line because of a permissions issue, when in fact it just needed to be called differently.

EG, instead of typing: traceroute 72.14.207.99

I needed to type: /usr/sbin/traceroute 72.14.207.99

With that being said, was able to design a script to do what I wanted:

Here it is if anyone is interested:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl -w
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI qw(:standard);
  7.  
  8. my $CIP = param('csrip');
  9.  
  10. my $trace;
  11. my $firstIP;
  12. my $eachHOP;
  13.  
  14. # only proceed if an IP address is entered via form
  15. if ($CIP =~ /\d.{1,3}\.\d.{1,3}\.\d.{1,3}\.\d.{1,3}/) {
  16.  
  17. # execute traceroute based on IP, do not perform DNS lookup
  18. # and send the first line of the response to the bit-bucket
  19. $trace = open(TRACE, "/usr/sbin/traceroute -n $CIP 2>/dev/null |");
  20. }
  21.  
  22. # if no IP address entered via form then die and do not proceed
  23. else {
  24.  
  25. die;
  26. }
  27.  
  28. # loop through the system output
  29. while ($firstIP = <TRACE>) {
  30.  
  31. # only take the first IP address on a line
  32. $firstIP =~ /\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+/;
  33.  
  34. $eachHOP = $1;
  35.  
  36. # prints each IP address on the hop path
  37. print "$eachHOP\n";
  38. }
  39.  
  40. close TRACE;
  41.  
  42.  
May 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephen Briley | last post by:
Hi all, I would like to write a python script that takes input of 2 ip address, one a start address and the other the end address and prints a list of all ip address in between in...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
8
by: john | last post by:
I would like to develope a system using a web or non-web based client (FrontPage, Access, etc.) that can send requests to various travel web site (using our user name and password for each) and...
1
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window....
3
by: Mam | last post by:
Hi I had developed one site,that site hides all the email addresses.Now i want to develope an application whose extract mail addresses from that site,Is there any solution to this.If u know how...
0
by: Mike Cox | last post by:
Andy M wrote: > ALERT > > There is a person by the name of Mike Cox who's trying > to turn this mailing list into a Big-8 newsgroup. No, I'm trying to get teh postgresql groups which are...
2
by: tthomas | last post by:
Greetings, I am using CDO.Message to send email messages from my application. I now need to send email to existing distribution lists in our Global Address List. However, our exchange server...
3
by: hillside | last post by:
I have hundreds of macros that use the SendObject action to email reports to several recipients. I need to compile a list of all recipients for each report. There are around 400 .mdb files with a...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.