Listen on port – client server demo

Problem

You want to listen on a port, maybe to test firewalls! 🙂

Excellent introduction to client server software.



Solution

Another use bit of socket programming, courtesy of Perl! 🙂

Extremely useful bit of Perl, which can be used with the other post on this site, to confirm network connectivity (port scanner).

This code (see example tab) will listen on a port (although be careful it is over 1024, unless you are running as root/admin).



Example



perl -MIO::Socket -e '$srv=IO::Socket::INET->
new(LocalPort=>$ARGV[0],Type=>SOCK_STREAM,Reuse=>1,Listen=>5)

or die "Failed trying to listen on $ARGV[0]n";while($cl=$srv->accept()) { while() { print }

} close($socket);' port

Can also use it as a cheap chat service! 🙂 Everything gets echo'd through – so just telnet host port and type away! 🙂

Also see my port scan code at the reference tab.



Reference

[tags]Perl Socket Programming, Network Programming, Perl Port Listen, Perl Client Server demo, Perl Coding School[/tags]



1 thought on “Listen on port – client server demo”

Leave a Reply

Your email address will not be published. Required fields are marked *