def vpn_ping(address, port, timeout=0.05, session_id=None):
 if (session_id is None):
  session_id = random.randint(0, 18446744073709551615L)
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 data = struct.pack('!BQxxxxx', 56, session_id)
 sock.sendto(data, (address, port))
 sock.settimeout(timeout)
 try:
  received = sock.recv(2048)
 except socket.timeout:
  return False
 finally:
  sock.close()
 fmt = '!BQxxxxxQxxxx'
 if (len(received) != struct.calcsize(fmt)):
  print struct.calcsize(fmt)
  return False
 (identifier, server_sess, client_sess) = struct.unpack(fmt, received)
 if ((identifier == 64) and (client_sess == session_id)):
  return server_sess

def vpn_ping ( address , port , timeout = 0.05 , session_id = None ) : if ( session_id is None ) : session_id = random . randint ( 0 , 18446744073709551615 L ) sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) data = struct . pack ( '!BQxxxxx' , 56 , session_id ) sock . sendto ( data , ( address , port ) ) sock . settimeout ( timeout ) try : received = sock . recv ( 2048 ) except socket . timeout : return False finally : sock . close ( ) fmt = '!BQxxxxxQxxxx' if ( len ( received ) != struct . calcsize ( fmt ) ) : print struct . calcsize ( fmt ) return False ( identifier , server_sess , client_sess ) = struct . unpack ( fmt , received ) if ( ( identifier == 64 ) and ( client_sess == session_id ) ) : return server_sess
sends a vpn negotiation packet and returns the server session .