示例#1
0
 def scan(self, param):
     ip = param['ip']
     port = param['port']
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.connect((ip, port))
         #print('{0}:{1} open'.format(ip,port))
         ipinfo = '{0}:{1}\n'.format(ip, port)
         lock.acquire()
         FileHelper.append(self.savepath, ipinfo)
         model = dict(ip=ip,
                      port=int(port),
                      flag=self.data_flag,
                      createdatetime=datetime.datetime.now())
         row_affect = SqlHelper.add(model)
         lock.release()
         s.close()
     except socket.timeout as e:
         s.close()
         try:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             s.connect((ip, port))
             #print('{0}:{1} open'.format(ip,port))
             s.close()
         except Exception as e:
             s.close()
     except Exception as e:
         s.close()
     self.scancount = self.scancount + 1
     sys.stdout.write('\r' + '已扫描:{0},剩余{1}'.format(
         self.scancount, self.taskcount - self.scancount))
     sys.stdout.flush()
 def scan(self, param):
     ip = param['ip']
     port = param['port']
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.connect((ip, port))
         str = '{0}:{1}\n'.format(ip, port)
         FileHelper.append(RESULT_PATH, str)
         s.close()
     except socket.timeout as e:
         s.close()
         try:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             s.connect((ip, port))
             #print('{0}:{1} open'.format(ip,port))
             self.open_ports.add({'ip': ip, 'port': port})
             s.close()
         except Exception as e:
             s.close()
     except Exception as e:
         s.close()
     self.scancount = self.scancount + 1
     sys.stdout.write('\r' + '已扫描:{0},剩余{1}'.format(
         self.scancount, self.taskcount - self.scancount))
     sys.stdout.flush()
示例#3
0
 def check_proxy_and_save(self, ip, port):
     if self.proxy_valid(ip, port):
         self.proxies.add(
             config.PROXY_DATA_TEMPLATE.format(ip=ip, port=port))
         lock.acquire()
         FileHelper.append(self.savepath, '{0}:{1}\n'.format(ip, port))
         lock.release()
         print('{0}:{1} 有效√'.format(ip, port))
     else:
         print('{0}:{1} 无效×'.format(ip, port))
    def prn(self, pkt):
        ip = pkt.sprintf('%IP.src%')
        port = pkt.sprintf('%IP.sport%')
        info = '{0}:{1}'.format(ip, port)
        fileipinfo = '{0}:{1}\n'.format(ip, port)
        #记得port要转换为整数
        if (int(port) in self.portlist) and (info not in self.result):
            self.result.add(info)

            FileHelper.append(self.savepath, fileipinfo)
            model = dict(ip=ip,
                         port=int(port),
                         flag=self.data_flag,
                         createdatetime=datetime.datetime.now())
            SqlHelper.add(model)