Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How accurate a portscan with Socket?

Status
Not open for further replies.

Raenius

Programmer
Oct 14, 2003
77
NL
Hi all,

I am trying to write something of a portscan utility for use in our company to check if our routers or computers are well defended, e.g. most ports are closed etc...

I saw some examples here on this forum, but my question was if you can't connect to it bu use of the socket module, is the port then properly closed?

Thanks!

- Raenius

"Free will...is an illusion"
 
Anyone have an idea?

"Free will...is an illusion"
 
This is the code I am using now:

foreach my $port (@ports)
{

if(my $sock = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => '1')) # or die print "Socket Error: $!"
{
print "Succesfully connected to port: $port\n";
}
else
{
print "Could not connect to port: $port\n";
}
}

Another question is: The Timou value does not work it takes about 5 - 10 seconds for the socket connection to die..

A third question would be how to optimalize this code to do this as fast as possible..

Greetz and thanks,

- Raenius

"Free will...is an illusion"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top