Check if certain Port is Open
Just needed to get to know whether something listens at a certain TCP port on a particular host.
Here is my workaround using Perl:
my $sock = IO::Socket::INET->new (
PeerAddr => "1.2.3.4",
PeerPort => 1337,
Proto => "tcp",
Timeout => 1
);
echo "closed" if !defined $sock;
Works at least for me. Any concerns or better solutions?
Leave a comment
There are multiple options to leave a comment:
- send me an email
- submit a comment through the feedback page (anonymously via TOR)
- Fork this repo at GitHub, add your comment to the _data/comments directory and send me a pull request
- Fill the following form and Staticman will automagically create a pull request for you:
1 comment
Two alternatives come to mind. First use
telnet
with a port number. For example (using values in your example):telnet 1.2.3.4 1337
You’ll have to know how to close the connection if there is a “Connected” message.
Second use
nmap
which is something sysadmins should get very familiar with. Here:nmap 1.2.3.4