473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

12 New Member
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 2329
eWish
971 Recognized Expert Contributor
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 New Member
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
4133
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 dotted-decimal format. If so, what is the recommended way? Is there a way to do this with the supplied python modules? Thanks!
17
3106
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 absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We...
8
1727
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 extract the requested pricing and information and compile it together for comparison. Can anyone suggest the best way to do this? I assumed XML would...
1
3032
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. Now that works fine so far. My problem is that while tracert process is running and ASP ..NET is putting data into the pages output stream, my...
3
2729
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 to extract or any related websites let me know.Because i have tried in so many ways but i didn't get the solution. Thanks in advance
0
2117
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 already ON usenet to follow proper usenet guidelines. In order to be under the comp.* hierarchy the server MUST go through RFD and CFV. Otherwise it...
2
12331
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 blocks sending to distribution list (i.e. distribution list is named MyDistList and its email address is MyDistList@mycompany.com) from SMTP email. ...
3
2032
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 total of around 4000 reports. Is there a way to programmatically extract the email addresses of the recipients from the macros?
45
4386
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
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.