1 Replies - 1467 Views - Last Post: 18 June 2013 - 10:10 AM Rate Topic: -----

#1 unname121992  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-June 13

[HELP] error in scan port with multi thread

Posted 06 June 2013 - 01:03 AM

Hello all,i'm newbie,i want to write a python script to scan multi IPs with multi ports,but my code is error,please help me
error :
Exception in thread Thread-2
Traceback (most recent call last):
FIle "C:\Python27\lib\threadiing.py",line 808,in __bootstrap_inner
FIle "C:\Python27\lib\threadiing.py",line 761,in run
typeError: connect() take 2 arguments(15 given)

import socket
import threading

class Scan(threading.Thread):
    def __init__(self):
  self.target_ip = ""
  self.ports = (22,80,445,1433,1521,3389,1,2,3,4,5,6,7,8,9,10)    

    #: # run chi chay khi co thread
  #   self.scan().start()

    def connect(self,IP):
    # connect to the given host:port
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((IP, self.ports))    
    print "%s:%d OPEN" % (IP, self.ports)
    except: pass

    def scan(self):    
  remoteServer_ = self.target_ip.split('-')
  remoteServer__ = remoteServer_[0].split('.')
    for ip in range(int(remoteServer__[3]),int(remoteServer_[1])+1):
    _ip_ = remoteServer__[0]+"."+remoteServer__[1]+"."+remoteServer__[2]+"."+str(ip)
    print "== IP: "+_ip_+" ==\n"
     # while threading.activeCount() < MAX_THREADS:
    threading.Thread(target=self.connect, args=(_ip_)).start() 
     #   self.ports.index += 1  
  except (socket.timeout, socket.error):
    return port, False

if __name__ == '__main__':
    raw_input('Please fill in questionnaire 1 and press [ENTER] when you are done.')


Is This A Good Question/Topic? 0
  • +

Replies To: [HELP] error in scan port with multi thread

#2 croog24  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 04-February 10

Re: [HELP] error in scan port with multi thread

Posted 18 June 2013 - 10:10 AM

By reading the error you will note that somewhere in your connect() function, you are supplying 15 arguments as opposed to the necessary 2 arguments.

The problem is in your connect() function, you are supplying the self.ports list as opposed to a single index within it. I noticed you tried to fix this with the "self.ports.index += 1" line, but that's not quite how it works :-p. Instead, you should add a port variable to your connect() function so that you can supply each port individually by iterating through your self.ports list.

Hope this helped!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1