开发者

MIRC Port Scanner

  if data.find('!scan') != -1:
     nick = data.split('!')[ 0 开发者_开发技巧].replace(':','')
     targetip = str(socket.gethostbyname(args))
     sck.send('PRIVMSG ' + chan + " :" ' scanning host' + " " + targetip + '\r\n')
     for i in range(20, 1025):
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         result = s.connect_ex((targetip, i))
         if (result == 0) :
              s.send('PRIVMSG ' + chan + " :" 'port %d: OPEN' % (i,) + '\r\n')
         s.close()

The script works, but it ping timeout before it can get an open port, how can I make it so it can scan a few ports then check for a ping from the server and send a pong then scan a few more ports so that it wont ping timeout.


The best solution is to use multiple threads, with the main thread parsing input from IRC and responding to PINGs, while other threads do actual command processing and anything that could take a long time.

skybot, my IRC bot, spawns a new thread whenever a command is issued, and uses thread-safe queues to pass messages between them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜