Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Proxy in perl

by santosh_wagh (Novice)
on Sep 10, 2012 at 07:15 UTC ( #992685=note: print w/ replies, xml ) Need Help??


in reply to Re: Proxy in perl
in thread Proxy in perl

All users are connected to one port switch this port is mirror where i have connected single machine with freebsd operating system.I am using Sniffer::HTTP module to catch the url.i want to block xyz.com for all users . i dont know how i can do it please find the following codes for your reference

#!/usr/bin/perl use strict; use Net::Pcap; use Sniffer::HTTP; use Net::RawIP; my $VERBOSE = 0; my $sniffer = Sniffer::HTTP->new( callbacks => { request => sub { my ($req,$conn) = @_; my $src = $conn->tcp_connection->src_host; my $sport = $conn->tcp_connection->src_port; my $dst = $conn->tcp_connection->dest_host; my $dport = $conn->tcp_connection->dest_port; my $myurl = $req->uri; if ( $myurl =~ "http://xyz.com" ) { system("/usr/bin/perl /myscripts/socket3.pl $dst $dport $src $sport"); } print "Request: $src:$sport -> $dst:$dport -> $myurl \n"; } }, ); $sniffer->run('alc0'); # uses the "best" default device

code of /usr/bin/perl /myscripts/socket3.pl

use Net::RawIP; $src_host = $ARGV[0]; # The source IP/Hostname $src_port = $ARGV[1]; # The Source Port $dst_host = $ARGV[2]; # The Destination IP/Hostname $dst_port = $ARGV[3]; # The Destination Port. $n = Net::RawIP->new({ ip => { saddr => "$src_host" , daddr => "$dst_host", }, tcp => { source => "$src_port", dest => "$dst_port", rst => 1, }, }); $n->send; $n->ethnew("alc0"); $n->ethset(source => "$src_host", dest => "dst_host" ); $n->ethsend;


Comment on Re^2: Proxy in perl
Select or Download Code
Re^3: Proxy in perl
by Corion (Pope) on Sep 10, 2012 at 07:26 UTC

    Please learn about TCP, and learn about what Sniffer::HTTP does.

    There is no way to modify the network connection or data using Sniffer::HTTP.

    Have you looked at the HTTP proxy modules on CPAN?

      Thanks for the reply. I had tried with squid ( squid working fine with Inline but not successful with span port ) . I will read HTTP:Proxy but can i block the url using span port. thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (18)
As of 2015-07-06 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls