LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-14-2006, 12:38 PM   #1
diablo_
Member
 
Registered: Dec 2005
Distribution: Slackware 11.0
Posts: 30

Rep: Reputation: 15
Perl (Port Scanner)


I was looking at perl today and it looked like a nice and easy language to me. Then i saw it has some network abillities and i was apsolutly thrilled. Now i have a small port scanner with only a few features

I wan't to make it better but i saw perl first time today so i need a little help, an idea.

Here is the source code:

Code:
#/usr/bin/perl -w
use IO::Socket;

print "Enter remote host adress: ";
chomp ($host=<STDIN>);
$hostip = inet_ntoa(inet_aton($host));
print "Enter port range\n";
print "From port: \n";
chomp ($fromport=<STDIN>);
print "To port: \n";
chomp ($toport=<STDIN>);
print "Host resolved to IP Address:'$hostip'\n";

while ($fromport<=$toport){
my $sock = IO::Socket::INET->new(proto=>'tcp', PeerAddr=>"$host", PeerPort=>$fromport) && print "Port '$fromport' found!\n";
$fromport++;
	
	if ($fromport==$toport) {
	close($sock);
	}

}
This is what i want to add/make better:

1. Reduce scanning time. There is timeout argument for IO::Socket::INET but i don't know how to use it. Tried, but didn't give any results. Also, couldn't find anything about it on the cpan, etc...

2. Description for every port. I wanted to create an array with descriptions (something like this):
Code:
@portdesc = ("","","","","","","","","","","","","","","","","","","","","ftp","","telnet","",
and it will take the $fromport-1 value to know for which one to write. But this looks like very boring job (there are 65535 ports!!!). So i was wondering anyone have a better idea?

3. Does anyone have an idea what should i add? I am just learning trough this example so this is nothing special remember.

Spasojevic Dimitrije

Last edited by diablo_; 12-14-2006 at 12:40 PM.
 
Old 12-14-2006, 01:33 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
use nmap
 
Old 12-14-2006, 01:58 PM   #3
diablo_
Member
 
Registered: Dec 2005
Distribution: Slackware 11.0
Posts: 30

Original Poster
Rep: Reputation: 15
I am. But nmap isn't helping me much about understanding this point of perl. Anyway i figured out answer to 2. question by using hashes.
 
Old 12-14-2006, 02:42 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Sorry about that. I was feeling cheeky.
 
Old 12-14-2006, 02:50 PM   #5
diablo_
Member
 
Registered: Dec 2005
Distribution: Slackware 11.0
Posts: 30

Original Poster
Rep: Reputation: 15
No problem. :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
port scanner and more ANU Linux - Software 1 05-26-2006 09:53 AM
Port scanner alon005 Linux - Security 1 10-14-2004 11:20 PM
Port Scanner Problem Alien18 Linux - Newbie 1 05-12-2004 08:44 PM
In need of the best port scanner there is! Pcghost Linux - Security 11 03-10-2003 09:37 AM
Port Scanner tfrye Linux - Security 1 04-18-2001 11:22 AM


All times are GMT -5. The time now is 09:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration