Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. # Utility to make a clean list of IP objects from
  2. # the dirty string of IP addresses
  3. # SO DIRTY
  4. def make_ip_list(ip_range_list):
  5.     pattern = re.compile(r"\d+\.\d+\.\d+\.\d+")
  6.     for i in range(len(ip_range_list)):
  7.         ip_range_list[i] = IP(pattern.search(ip_range_list[i]).group(0))
  8. #        print ip_range_list[i]
  9.     return ip_range_list
  10.  
  11. # Utility to find router ID for an arbitrary IP address
  12. # Handy!
  13. def router_id_from_ip(ip_list, ip_addr):
  14.     return bisect.bisect_left(ip_list, ip_addr)
  15.  
  16. # Makes a 2D array for the routing table
  17. # It is flipped about the diagonal from how
  18. # one would initially think of it from the string
  19. def make_routing_table(id_list, dimension):
  20.     routing_table = []
  21.     for i in range(dimension):
  22.         routing_table.append([])
  23.         for j in range(dimension):
  24.             routing_table[i].append(id_list.pop(0))
  25.     return routing_table
  26.  
  27. # Utility to look at the routing table
  28. # and make sure its not malformed
  29. def print_routing_table(routing_table):
  30.     for i in range(len(routing_table)):
  31.         for j in range(len(routing_table)):
  32.             sys.stdout.write(routing_table[i][j])
  33.             sys.stdout.write(" ")
  34.         sys.stdout.write("\n")
  35.  
  36. # Utility func... wait.
  37. def main():
  38.     sockets = []
  39.     for i in range(5):
  40.         sockets.append(socket.socket(AF_INET, SOCK_STREAM))
  41.         try:
  42.             sockets[i].connect(('dio.cs.umn.edu',5001))
  43.         except socket.error, msg:
  44.             sockets[i].close()
  45.             print 'Could not open socket'
  46.             print str(msg)
  47.             sys.exit(1)
  48. #        sockets[i].settimeout(0.1) #Non-block for the win
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement