python实现探测socket和web服务示例

2019-10-06 18:02:18于海丽

                        if re.findall('^500d*','%s' %e.code):
                                port_500.append('1')
   if re.findall('^502d*','%s' %e.code):
    port_502.append('1')
                        if re.findall('^503d*','%s' %e.code):
                                port_503.append('1')
  else:  
   port_other.append('1')
 else:
                port_normal.append('1')

def Detect_socket(server,port):
 sign = 0
        if timeout:
                time = int(timeout)
        else:
                time = 1

 socket.setdefaulttimeout(time)
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 try:
  ret = s.connect((server, int(port)))
 except socket.error, e:
  if re.findall('^timed out*','%s' %e):
   socket_timeout.append('1')
   sign = 1
  else:
   print '%s' %e
   sys.exit(2)
 else:
  socket_normal.append('1')
  sign = 1
 if sign == 0:
  s.close()

def print_out():
 if url_mod:
  print 'URL:'
         print 'timeout:[%s]' %len(port_timeout)
         print 'normal:[%s]' %len(port_normal)
         print '33[;31mError_403:[%s]tError_404:[%s]33[0m' %(len(port_403),len(port_404))
         print '33[;31mError_500:[%s]tError_502:[%s]tError_503:[%s]33[0m' %(len(port_500),len(port_502),len(port_503))
  print '33[;31mError_other:[%s]33[0m' %len(port_other)

 if sock_mod:
  print 'Socket:'
         print 'timeout:[%s]' %len(socket_timeout)
          print 'normal:[%s]' %len(socket_normal)
    

def main():
 if sock_mod:
  dest_arg1 = sock_mod
  dest_arg2 = dport
  dest_function = Detect_socket