Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Utility to make a clean list of IP objects from
- # the dirty string of IP addresses
- # SO DIRTY
- def make_ip_list(ip_range_list):
- pattern = re.compile(r"\d+\.\d+\.\d+\.\d+")
- for i in range(len(ip_range_list)):
- ip_range_list[i] = IP(pattern.search(ip_range_list[i]).group(0))
- # print ip_range_list[i]
- return ip_range_list
- # Utility to find router ID for an arbitrary IP address
- # Handy!
- def router_id_from_ip(ip_list, ip_addr):
- return bisect.bisect_left(ip_list, ip_addr)
- # Makes a 2D array for the routing table
- # It is flipped about the diagonal from how
- # one would initially think of it from the string
- def make_routing_table(id_list, dimension):
- routing_table = []
- for i in range(dimension):
- routing_table.append([])
- for j in range(dimension):
- routing_table[i].append(id_list.pop(0))
- return routing_table
- # Utility to look at the routing table
- # and make sure its not malformed
- def print_routing_table(routing_table):
- for i in range(len(routing_table)):
- for j in range(len(routing_table)):
- sys.stdout.write(routing_table[i][j])
- sys.stdout.write(" ")
- sys.stdout.write("\n")
- # Utility func... wait.
- def main():
- sockets = []
- for i in range(5):
- sockets.append(socket.socket(AF_INET, SOCK_STREAM))
- try:
- sockets[i].connect(('dio.cs.umn.edu',5001))
- except socket.error, msg:
- sockets[i].close()
- print 'Could not open socket'
- print str(msg)
- sys.exit(1)
- # sockets[i].settimeout(0.1) #Non-block for the win
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement