use IO::Socket; use Net::Pcap; use NetPacket::Ethernet qw(:strip); use NetPacket::TCP; use NetPacket::IP qw(:strip); use List::Util qw(first); # Find all interfaces. my @interfaces = Net::Pcap::findalldevs(\%devinfo, \$err); my $int = first { $devinfo{$_} =~ /Real/ } @interfaces; #print $int; in my case i want to find Realtech interface $snaplen = 1515; #Package lenght $promisc = 1; #Captur packages in promiscious mode $timeout = 30; $count = 12; # (count = 0 = forever) here is the number of packages you want to capture my $pcap = Net::Pcap::open_live( $int,$snaplen,$promisc,$timeout,\$err ); #Select the interface you want to capture packages , and it's information my $socket = new IO::Socket::INET ( PeerAddr => '192.168.11.244', PeerPort => '6008', Proto => 'tcp', ); die "Couldn't connect: $!\n" unless $socket; $data = pack("CccccccCcCC",02,65,63,80,81,76,86,03,100,13,10); if ( $socket ) { print $socket $data ; Net::Pcap::loop($pcap, $count, \&callback, $user_data); sleep 1; # the device takes 1 second to answer } close($socket); sub callback { my ($user_data, $header_ref, $packet) = @_; $ip = NetPacket::IP->decode(eth_strip($packet)); $tcp = NetPacket::TCP->decode($ip->{data}); if ( $tcp->{src_port} == 6008 ) { $payload = $tcp->{data}; print "$ip->{src_ip}:$tcp->{src_port} --> $ip->{dest_ip}:$tcp->{dest_port} Payload: $payload\n"; } }