Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Writing a port scanner...

  1. #1
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953

    Post Writing a port scanner...

    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...
    yeah, I\'m gonna need that by friday...

  2. #2
    Junior Member
    Join Date
    Sep 2002
    Posts
    21
    mmm that's interestin , i'll try to make something

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,785
    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.


    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  4. #4
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953
    #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);
    }
    yeah, I\'m gonna need that by friday...

  5. #5
    Senior Member SodaMoca5's Avatar
    Join Date
    Mar 2002
    Posts
    236
    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.
    SodaMoca5
    \"We are pressing through the sphincter of assholiness\"

  6. #6
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953
    What other kewl net-tools would everybody like to see explained? Please- nothing too complicated- this is for newbies...
    yeah, I\'m gonna need that by friday...

  7. #7
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    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
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  8. #8
    Senior Member SodaMoca5's Avatar
    Join Date
    Mar 2002
    Posts
    236
    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.
    SodaMoca5
    \"We are pressing through the sphincter of assholiness\"

  9. #9
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    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
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  10. #10
    Senior Member SodaMoca5's Avatar
    Join Date
    Mar 2002
    Posts
    236
    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,
    SodaMoca5
    \"We are pressing through the sphincter of assholiness\"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •