Results 1 to 5 of 5

Thread: Port Scan

  1. #1

    Port Scan

    Code:
    #!/usr/bin/perl
    
    use IO::Socket;
    
    $message = "DIE SCUM\n\n\n";
    $message2 = "JERK!\n\n\n";
    
    my $socket = IO::Socket::INET-> new (LocalAddr => 'localhost', 
     * * * * * * * * * * * * LocalPort => 23, 
     * * * * * * * * * * * * Listen => 10, 
     * * * * * * * * * * * * Proto => 'tcp') || die $_;
    
    while($con = $socket->accept)
    {
     * * *print $con $message;
     * * *$a[0] = $con->peerhost;
     * * *print "CONNECTION from $a[0] \n\n";
     * * *if($a[0] eq $a[1]) { print $con $message2; }
     * * *$a[1] = $a[0];
     * * *close($con);
    
    }

  2. #2
    Guest

    Re: Port Scan

    shouldn't this be in the programming forum?

    btw, i got one word for u: 8) nmap 8)

  3. #3

    Re: Port Scan

    Ashcrow: for us non-programmers, what does that do, and how would some of us use what you put up here?

  4. #4
    Guest

    Re: Port Scan

    Python:
    Code:
    #!/usr/bin/env python
    
    from socket import *
    import sys, signal
    
    
    
    class Scanner:
     def scan(self, host, port):
    
      if int(port) > 65535:
       limit = 65536
      else:
       try:
        limit = int(port) + 1
       except ValueError:
        print "Invalid port number"
        sys.exit(1)
    
      for x in xrange(limit):
       s = socket(AF_INET, SOCK_STREAM)
       try:
        s.connect((host, x))
       except error:
        continue
       print " -> Port \33[1m%5s\33[0m is \33[1;32mopen\33[0m" % x
       s.close()
    
    
    def stop(*args):
     print "Scan interrupted by user"
     sys.exit(0)
    
    
    def main():
     signal.signal(signal.SIGINT, stop)
    
     if len(sys.argv) < 3:
      print "Usage: %s <hostname> <highest port to scan>" % sys.argv[0]
      sys.exit(1)
    
     s = Scanner()
     s.scan(sys.argv[1], sys.argv[2])
    
    
     print "Scan completed"
    
    if __name__ == '__main__':
     main()
    Ruby:
    Code:
    #!/usr/bin/env ruby
    
    require 'socket'
    
    trap "INT" do
     puts "\nScan interrupted"
     exit 0
    end
    
    class Scanner
     def scan(host, port)
    
      begin 
       limit = Integer(port)
      rescue
       puts "Error: port number must be an integer"
       exit 1
      end
    
      limit.times do |x|
       begin
        t = TCPSocket.new(host, x)
       rescue Errno::ECONNREFUSED
        next
       end
       puts " -> Port \33[1m#{x}\33[0m is \33[32mopen\33[0m"
       t.close
      end
      
     end
    end
    
    
    
    def main
    
     if ARGV.length < 2
      puts "Usage: #{$0} <hostname> <highest port to scan>"
      exit 1
     end
    
     scan = Scanner.new
     scan.scan(ARGV[0], ARGV[1])
    
     puts "Scan completed"
    end
    
    if $0 == __FILE__
     main
    end
    Usage for both scanners: scan <host to scan> <highest port to scan>

  5. #5

    Re: Port Scan


    Ashcrow: for us non-programmers, what does that do, and how would some of us use what you put up here?
    It's here for a joke. What it does is when someone connects to port 23 it displays message, and if they connect a second time it displays both message and message2. A friend of mine was sick of ppl testing to see if port 23 (telnet) was open so I wrote that. It works, but it's flaky :P

Similar Threads

  1. Scan Port 22
    By shebang in forum Linux - Hardware, Networking & Security
    Replies: 6
    Last Post: 12-05-2004, 10:28 PM
  2. dual port net card: port trunking?
    By Blaqb0x in forum Linux - Hardware, Networking & Security
    Replies: 0
    Last Post: 02-06-2003, 10:33 PM
  3. SMTP port not showing up on local scan
    By Blaqb0x in forum Linux - Hardware, Networking & Security
    Replies: 1
    Last Post: 07-21-2002, 02:46 PM
  4. shares not viewable on server even with port scan
    By doggiebone in forum Linux - Hardware, Networking & Security
    Replies: 8
    Last Post: 06-25-2002, 10:48 PM
  5. Port Scan Warning Program?
    By datamike in forum Linux - Hardware, Networking & Security
    Replies: 4
    Last Post: 03-27-2002, 06:52 PM

Bookmarks

Posting Permissions

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