Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2004, 07:47 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
scan program

Im tring to create a port scanner ( knowledge only ) but for some reason it just halts. I mean it does not want to scan anything.. any idea?

Code:
BUFF_SIZE      = 1024

def Scan_Host( ):

        for ports in range( 1, BUFF_SIZE ):

                host   =  "localhost"
                sock   = socket.socket( socket.AF_INET, socket.SOCK_STREAM )

                if sock.connect_ex(( host, int( ports ))):

                        print ports, '/tcp'


if __name__ == '__main__':

                Scan_Host( )

Reply With Quote
  #2  
Old June 9th, 2004, 08:53 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Try replacing "print ports, '/tcp' with:
Code:
sys.stdout.write("%i/tcp" % port)
sys.stdout.flush()

Reply With Quote
  #3  
Old June 9th, 2004, 09:17 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Ok sorry i just realized that it scans.. but it takes a really really long time.. is there a way to speed it up abit?

Reply With Quote
  #4  
Old June 10th, 2004, 11:31 AM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 10
A long time indeed. The default socket timeout is 30 seconds, which means 8 hours for a full scan of your 1024 ports.

Check socket.settimeout(s) to lower the time.
Also consider threading.

Incidentally, BUFF_SIZE? Not max_port_no?

Reply With Quote
  #5  
Old June 10th, 2004, 01:10 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Yes its what i did.. i whent along with using threading.. but... when i try it out on linux.. everything works well.. but on windows.. thats another case.. i keep getting an error about Undefine name Thread cant seem to think why cause everything seems to be in place

This is when running it on cmd ( python gui consule works )

Code:
Traceback (most recent call last):
  File "progs/pscanner.py", line 6, in ?
    class PortScan( Thread ):
NameError: name 'Thread' is not defined


when i try to wrapp it with py2exe i get the same error

Code:
class Scan( Thread ):

        def __init__ ( self, uhost, port ):
                Thread.__init__( self )

                self.host  = uhost
                self.port  = port

        def run( self ):
                
                try:
                    sock  = socket( AF_INET, SOCK_STREAM )
                    sock.connect(( self.host, self.port ))

                    print '%d/tcp \t Open' % self.port
                    
                    sock.close( )

                except error:
                    pass

              
                


if __name__ == '__main__':

                try:
                    
                    hosts  = argv[1]
                    ports  = int( 664 )

                    e = Event( )
                    
                    for Ports in range( 1, ports ):
                        
                            try:
                                    if( activeCount( ) >= ports ):
                                        
                                            e.clear( )
                                            e.wait( )

                                    start_scan   = Scan( hosts, Ports )
                                    start_scan.start( )
                                    
                            except error:
                                    pass

                except IndexError:
                    
                        print 'Usage: %s <host/ip address>' % argv[0]

Last edited by xlordt : June 10th, 2004 at 01:14 PM.

Reply With Quote
  #6  
Old June 10th, 2004, 01:32 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
Code:
from threading import Thread

??
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #7  
Old June 10th, 2004, 01:35 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by Grim Archon
Code:
from threading import Thread

??


I was just tring it out.. cause got kinda mad cause.. it wasnt working , i still get that damn erro.. since last night i have been tring ti figure out what is up.. did what you said.. and now i get..
Code:
Traceback (most recent call last):
  File "progs/pscanner.py", line 2, in ?
    from threading import Thread
ImportError: cannot import name Thread

Reply With Quote
  #8  
Old June 10th, 2004, 01:57 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 10
Are you running the latest version of Python?

Reply With Quote
  #9  
Old June 10th, 2004, 02:00 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
hmm weird i just opend the python idle it said.. im running 2.3.2.. will download the latest then see whats up, but im sure i downloaded the latest version

Reply With Quote
  #10  
Old June 10th, 2004, 02:06 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Ok just upgraded to 2.3.4 and im still getting the same problem arg!!

Code:
from socket import *
from threading import *
from sys import argv


error:
Code:
G:\Python23>python.exe progs/pscanner.py
Traceback (most recent call last):
  File "progs/pscanner.py", line 6, in ?
    class Scan( Thread ):
NameError: name 'Thread' is not defined


the module is there cause i checked

Last edited by xlordt : June 10th, 2004 at 02:09 PM.

Reply With Quote
  #11  
Old June 10th, 2004, 08:01 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
I put the import statements in the same file as the Scan class.

I had to check that
from socket import * did not get stuff replaced by
from threading import * (nasty code )

On my Windows machine it did not cause any problem and ran as expected.

On my Redhat machine it caused threading to complain after port 68 saying thread.error: can't start new thread but did scan up to that number I think.

It may be some Linux security limit I am not aware of but what it looks like to me is an implementation difference.

Not sure (it's late) if the code should run at all but I just ran it under Python 2.2 on my redhat machine and it got upto port 663 but did not report back any results.

grim

Last edited by Grim Archon : June 10th, 2004 at 08:09 PM.

Reply With Quote
  #12  
Old June 10th, 2004, 10:46 PM