|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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( )
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#2
|
|||
|
|||
|
Try replacing "print ports, '/tcp' with:
Code:
sys.stdout.write("%i/tcp" % port)
sys.stdout.flush()
|
|
#3
|
||||
|
||||
|
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?
|
|
#4
|
|||
|
|||
|
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? |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
||||
|
||||
|
Code:
from threading import Thread ??
__________________
*** Experimental Python Markup CGI V2 *** |
|
#7
|
||||
|
||||
|
Quote:
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
|
|
#8
|
|||
|
|||
|
Are you running the latest version of Python?
|
|
#9
|
||||
|
||||
|
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
|
|
#10
|
||||
|
||||
|
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. |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|
|
|