scan network port with perl

[problem]

You want to test a network port, on a remote system – over TCP/IP.

Maybe this is a new setup, or you want confirmation it is working.

Perhaps the firewall rules have just been changed! 🙂

[/problem]

[solution]

A nice small bit of Perl code that I’ve used thousands of times!

In fact I’m running it in most of my production environments,
as a check that the a process is not only running – but also responding.

Yep, you could just use telnet – but some systems have that taken off for security.

Additionally it is n’t as easy to program telnet – I know, I know – you can with expect. 🙂

[/solution]

[example]

Here is just a one liner, but you can easily incorporate this into a script.

perl -MIO::Socket -e '$socket=IO::Socket::INET->
new(Proto=>tcp,PeerAddr=>$ARGV[0],PeerPort=>$ARGV[1]);
if([email protected]) { print "Failed: [email protected]" } else { print "Succeedn"; }' host port

[/example]

[reference]

[tags]Perl, Network, TCPIP, Port Scanner, Perl Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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