473,218 Members | 1,498 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,218 software developers and data experts.

Why did the packet capture program did not print any info like IP addr and port??


I tried the packet capture module program.
I did a file transfer using ftp from this host to another server.

But when I ran the program, it was just hanging off and it did not print the src ip, dst ip, src port, dst port.

Should I run this program as a Daemon? If so, how do I do that?

I would appreciate your response.

This is the code that is tried and I got this on this http://www.perlmonks.org/node_id=170648 website:

Expand|Select|Wrap|Line Numbers
  1. use Net::Pcap;
  2. use NetPacket::Ethernet;
  3. use NetPacket::IP;
  4. use NetPacket::TCP;
  5. use strict;
  7. my $err;
  9. #   Use network device passed in program arguments or if no 
  10. #   argument is passed, determine an appropriate network 
  11. #   device for packet sniffing using the 
  12. #   Net::Pcap::lookupdev method
  14. my $dev = $ARGV[0];
  15. unless (defined $dev) {
  16.     $dev = Net::Pcap::lookupdev(\$err);
  17.     if (defined $err) {
  18.         die 'Unable to determine network device for monitoring - ', $e
  19. +rr;
  20.     }
  21. }
  23. #   Look up network address information about network 
  24. #   device using Net::Pcap::lookupnet - This also acts as a 
  25. #   check on bogus network device arguments that may be 
  26. #   passed to the program as an argument
  28. my ($address, $netmask);
  29. if (Net::Pcap::lookupnet($dev, \$address, \$netmask, \$err)) {
  30.     die 'Unable to look up device information for ', $dev, ' - ', $err
  31. +;
  32. }
  34. #   Create packet capture object on device
  36. my $object;
  37. $object = Net::Pcap::open_live($dev, 1500, 0, 0, \$err);
  38. unless (defined $object) {
  39.     die 'Unable to create packet capture on device ', $dev, ' - ', $er
  40. +r;
  41. }
  43. #   Compile and set packet filter for packet capture 
  44. #   object - For the capture of TCP packets with the SYN 
  45. #   header flag set directed at the external interface of 
  46. #   the local host, the packet filter of '(dst IP) && (tcp
  47. #   [13] & 2 != 0)' is used where IP is the IP address of 
  48. #   the external interface of the machine.  For 
  49. #   illustrative purposes, the IP address of is 
  50. #   used in this example.
  52. my $filter;
  53. Net::Pcap::compile(
  54.     $object, 
  55.     \$filter, 
  56.     '(dst && (tcp[13] & 2 != 0)', 
  57.     0, 
  58.     $netmask
  59. ) && die 'Unable to compile packet capture filter';
  60. Net::Pcap::setfilter($object, $filter) &&
  61.     die 'Unable to set packet capture filter';
  63. #   Set callback function and initiate packet capture loop
  65. Net::Pcap::loop($object, -1, \&syn_packets, '') ||
  66.     die 'Unable to perform packet capture';
  68. Net::Pcap::close($object);
  71. sub syn_packets {
  72.     my ($user_data, $header, $packet) = @_;
  74.     #   Strip ethernet encapsulation of captured packet 
  76.     my $ether_data = NetPacket::Ethernet::strip($packet);
  78.     #   Decode contents of TCP/IP packet contained within 
  79.     #   captured ethernet packet
  81.     my $ip = NetPacket::IP->decode($ether_data);
  82.     my $tcp = NetPacket::TCP->decode($ip->{'data'});
  84.     #   Print all out where its coming from and where its 
  85.     #   going to!
  87.     print
  88.         $ip->{'src_ip'}, ":", $tcp->{'src_port'}, " -> ",
  89.         $ip->{'dest_ip'}, ":", $tcp->{'dest_port'}, "\n";
  90. }
Jun 26 '07 #1
1 3326
3,509 Expert Mod 2GB
This is the code that is tried and I got this on this http://www.perlmonks.org/node_id=170648 website:
First, I tried to go to the link to PerlMonks, but it isn't there (just a nice 404 page).

My suggestion is to wander back over to PerlMonks (and hopefully to the correct URL) and re-read the page to see if it gives you more information about how to run it and such. Also, if that does not work, then you may want to pose the question to PerlMonks by posting a node. It takes only a couple minutes to sign up over there if you haven't already and the community itself is quite rich with knowledge.


Jun 30 '07 #2

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

Similar topics

by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. ...
by: Simon | last post by:
Hi everyone, I'd quite like to create a small application that could listen on a port and take a copy of any communications going in or out. The end goal is to be able to offer statistics and...
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
by: pmm | last post by:
hi I am a beginner in network programming I am trying out a UDP packet transfer between a windows machine and a linux I created a structure on both sides (ie on linux and on windows) and I sent...
by: diffuser78 | last post by:
Hi, I have the following code for a cline and server which I got from a small tutorial on the web. #!/ usr/bin/env python # tms.py (SERVER) import socket import sys
by: Sagittarius | last post by:
I will first try to describe my problem in words. I have a simple program, written in C++, that needs to send a single bytearray via a UDP socket to a microprocessor, which returns an answer, also...
by: nexus024 | last post by:
I am trying to write a program that will continuously sniff eth0 for a specific UDP packet thats being sent to a specific destination IP, alter the data of the packet, and finally transmit it to the...
by: neeru29 | last post by:
I'm using Pcapy and impacket module for packet sniffer. I'm able to capture the whole data in a variable and display it. I want extract the IP addresses , Port no's and Payload data into separate...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.