I hope you guys/gals like this short tutorial. It's kinda small but should be enough to explain the subject matter.
A simple port scanner project for newbie programmers...
Printable View
I hope you guys/gals like this short tutorial. It's kinda small but should be enough to explain the subject matter.
A simple port scanner project for newbie programmers...
mmm that's interestin , i'll try to make something :)
so what am i doing wrong?
C:\>wonderful.pl
Number found where operator expected at C:\wonderful.pl line 12, near "$begin = ("1"
(Might be a runaway multi-line "" string starting on line 10)
(Missing operator before 1?)
String found where operator expected at C:\wonderful.pl line 14, near "$maxport = (รด65535""
(Might be a runaway multi-line "" string starting on line 12)
(Missing semicolon on previous line?)
syntax error at C:\wonderful.pl line 12, near "$begin = ("1"
Execution of C:\wonderful.pl aborted due to compilation errors.
#Sorry about that- The code in there, for the most part, was for show... Here is a working Copy of the same script...
#!/usr/bin/perl
print "\n\nPort Scanner\n\n";
use IO::Socket;
my ($line, $port, $sock, @servers);
my $VERSION='1.0';
($server = $ARGV[0]) || &usage;
$begin = ($ARGV[1] || 0);
$maxport = ($ARGV[2] || 0);
for ($port=$begin;$port<=$maxport;$port++) {
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
if ($sock) {
print "::$port [passed]::\t\t\t";
} else {
print "::$port [failed]::\t\t\t";
}
} # End for
sub usage {
print "\nUsage: portscan hostname [start at port number] [end at port number]\n";
exit(0);
}
Thank you, used your working code, then manipulated it a bit for user input. Will probably manipulate it further so I can put in individual ports and have it test only the ones I really want checked.
However just seeing your snippet opened up the way to test a port and now I can use that basic knowledge to further my very slight programming skill a bit more in the direction I want to go.
What other kewl net-tools would everybody like to see explained? Please- nothing too complicated- this is for newbies...
Heh heh heh, maybe you could take my quick and dirty SMTP scanner and explain it, it goes a step beyond just connecting to a port to see if it is open, I will say though, I have made a few tweaks/bug fixes since I posted that script (And then used it to identify a mind numbing number of relays...grrr...at least fixed now).
The original posting was here:
http://www.antionline.com/showthread...hreadid=235929
If not taking the original, it might at least give you a good start or an idea for something else, like maybe implementing something like the tool wget. Ie, a program that actually sends/receives a little data (take your example a step further).
/nebulus
You asked what others I would like to see. Well I don't know how simple it is because my programming skills are pretty basic. I would like to see the code to read in the TCP/IP data coming into a machine. I guess I would like to see a basic sniffer or the parser that would lead to a basic sniffer.
If this is easy then just a few hints about what direction to take would be good as well. I am currently learning Perl so the examples being in Perl are great for me.
Well, the thread has the source code with a fair amount of comments, so it might be something you could learn from, but it was kind of beside the point. The next logical step in doing socket programming (after learning how to make connections) is to actually talk to something on the other end. There is a program that allows you to grab webpages/files from webservers from the command line in unix (useful if you only have a shell and need to download afile off of the web server) and it is called wget. That might be something that would be neat to do in perl because it would show actually sending commands to the HTTP server, issuing the gets, etc. It would not only cover the socket programming in perl but it would also cover the basics of the HTTP protocol and 'how to talk it'... was just a suggestion though...kinda tempted to do it myself now :)
/nebulus
Nebulus:
I downloaded your text file and am starting to go through it. Thanks for the input. BTW as to my earlier request I have not done a search to see if one is in the tutorials (my bad) I will do so in a bit and post it back here if I can. I find that reading your snippets of code and figuring out how they work helps me to leap frog some of the steps I have been taking with my perl learning. I am still following the text I am studying but it is always nice to get a glimpse of where I am heading as well as just the section of the road I am currently on.
Sincerely,
Hmm....when I actually started using the script I ran across some things that didn't work quite right, so here is the updated fixed script with the original functionality (some of which I removed from the one I posted)
/nebulus
#The following code was taken out of an old 2600 I found under my bed :-)
#Print's Header information from a http request.
use HTTP::Response;
use LWP::UserAgent;
my $au = new LWP::UserAgent;
$au->agent('891681651651_981651651651');
my $req = new HTTP::Request(GET, "http://$ARGV[0]");
print $headers = $au->request($req)->headers_as_string;
For those of you that like the code and are using it, i thought it would be helpful if you guys had a list of the ports and common services associated with those ports... You can find a lit of such services here at http://www.hackerwhacker.com/portslist.html ... I hope this helps...
I just added a little feature to your code that is useful to me, sending the output to a file. You could always redirect it, but I figure things should all be contained in the code. It's just a simple:
open(PORTS, ">ports.log") || die "Can't open output file.\n";
then adding PORTS between the print statement and the text like
print PORTS "::$port [passed]::\n";
For you sys admins, this could even be exteneded to naming the file "$ENV{'computername'}-ports.log" (in win2k anyway)(choose the proper environment var. for your OS), saving it to a shared folder and deploying it as part of the login script. It would have to run at night or something since it takes some time....
Lots of great uses for this scanner. Excellent work!
Is this code not for windows.If you know any C# could you try to do your next tutorial in this language.That is about the only language I am familiar with besides some smaller languages.
Cool What did you write it in, man? Looks like perl, the thing about me is that once I get used to a language I get bored of it then completly forget everything I've learned once I've managed to move onto something else. lol
I haven't developed too many tools until now, but this is a nice addition to my small, but expanding collection.
THX for the info.