Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Hooking the winsock

by coec (Chaplain)
on Mar 16, 2004 at 08:00 UTC ( [id://336946]=note: print w/replies, xml ) Need Help??


in reply to Hooking the winsock

If you are wanting to see who is probing tcp/80 (http) then you could use IO::Socket and get the details of the client. Google turned this up for me... http://www.infocopter.com/perl_corner/socket-server.htm
#!/usr/bin/perl -w # server0.pl #-------------------- use strict; use Socket; # use port 7890 as default #my $port = shift || 7890; my $port = 80; my $proto = getprotobyname('tcp'); my $logfile = "/tmp/logfile"; # create a socket, make it reusable socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!"; # grab a port on this machine my $paddr = sockaddr_in($port, INADDR_ANY); # bind to a port, then listen bind(SERVER, $paddr) or die "bind: $!"; listen(SERVER, SOMAXCONN) or die "listen: $!"; print "SERVER started on port $port\n"; # accepting a connection my $client_addr; while ($client_addr = accept(CLIENT, SERVER)) { # find out who connected my ($client_port, $client_ip) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr($client_ip, AF_INET); # print who has connected open(OUT, ">$logfile"); print OUT "got a connection from: $client_host", "[$client_ipn +um]\n"; close(OUT); # send them a message, close connection #print CLIENT "Smile from the server"; close CLIENT; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-28 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found