def searchIP(): ip = IP() count = 0 global ipList if verbose == "0": #No verbosity spinner = Spinner('I m Computing...') while (count < desiredIP): spinner.next() try: r = pyping.ping(ip.generateRandomIP4()) if r.ret_code == 0: dnsReverse(r.destination) ipList.insert(count, r.destination) count = count + 1 except: print("") elif verbose == "1": #verbosity while (count < desiredIP): ipGenerato = ip.generateRandomIP4() print "\nGenerated IP4: " + ipGenerato print "\nTesting it\n" try: r = pyping.ping(ipGenerato) if r.ret_code == 0: print r.destination + " " + "reachable" dnsReverse(r.destination) ipList.insert(count, r.destination) count = count + 1 elif r.ret_code == 1: print r.destination + " " + "unreachable" except: print("") return
def __init__(self): self.__nome = "" EquipamentoRede.__init__(self) self.__tRotas = TabelaRotas() self.__IP = IP() self.__ICMP = ICMP(self) self.__ip = "" self.__mac = "" self.__novoQuadro = None self.__quadro = None
def getIP(): while True: ip = raw_input("Introduce la IP: \t") ip = IP(ip) #Si la IP no es valida la vuelve a solicitar if not ip.validar(): print "IP no válida" continue break return ip
def on_login(self, name): ip = IP(self.address[0]) result = self.protocol.ipcheck.check_ip(ip) log_msg("Player \"%s\" IP ADRRESS INFO: %s" % (name, str(result)), self.protocol, info=True) return connection.on_login(self, name)
def _get_ip_info(self, ip): if ip == IP("127.0.0.1") or ip == IP( "255.255.255.255") or ip.ip[0] == 192: return json.loads( '{"status": "ok", "127.0.0.1": {"type":"localhost"}}'), False if self._ip_already_exists(ip): return self._get_ip_info_from_cache(ip), True r = requests.get(REQUEST_FORMAT % (ip, self.api_key)) if r.status_code == HTTP_OK: self._new_cache_entry(ip, r.json()) return r.json(), False elif r.status_code == HTTP_FORBIDDEN: return json.loads('{"status": "forbidden"}'), False elif r.status_code == HTTP_BAD_GATEWAY: return json.loads('{"status": "bad_gateway"}'), False elif r.status_code == HTTP_NOT_FOUND: return json.loads('{"status": "not_found"}'), False elif r.status_code == HTTP_INTERNAL_SERVER_ERROR: return json.loads('{"status": "internal_server_error"}'), False
def Receive(sniffer=None): if not sniffer: return None try: # 65565不是端口号是缓存大小 raw_buffer = sniffer.recvfrom(65565)[0] ip_header = IP(raw_buffer[0:20]) # print(" Version:%s \n Protocol:%s \n Len:%s \n Src:%s -> Dst:%s\n Time:%s\n" # % ( ip_header.version_,ip_header.protocol, ip_header.len_, ip_header.src_, # ip_header.dst_, time()) # ) return [strftime('%Y-%m-%d %H-%M-%S', localtime(time())), ip_header.version_, ip_header.protocol, ip_header.src_, ip_header.dst_, ip_header.len_] except KeyboardInterrupt: if os.name == "nt": sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
def getAddresses(self): ip_addresses = [] ip_address_objects = [] # list of IP objects description = self.issue.fields.description # grab description for line in description.splitlines(): # loop through all lines in description if line.startswith('First IP:') or line.startswith(('Next IP:')): # find line that starts with it provides for word in line.split(): # split line into array of words if word[0].isdigit(): # if it is an ip address add to list ip_addresses.append(word) for ip in ip_addresses: # loop through all ip addresses returned try: location_info = IP(ip) # create object from ip address self.locations.append([float(location_info.longitude), float(location_info.latitude)]) ip_address_objects.append(location_info) # append to list except Exception as e: location_info = "n/a" return ip_address_objects
class TabelaRotas(): def __init__(self): self.__ip = IP() self.__listaRotas = [] self.__default = None "@param ip: destination host ip" def encontrarRota(self, ip): # Routing algorithm for linha in self.__listaRotas: if linha.getDestino() == self.__ip.netID(ip, linha.getMascara()): return linha return None def getLRotas(self): return self.__listaRotas "@param rota: new route" def addRota(self, rota): self.__listaRotas.append(rota) "@param ip: ip to remove route" def removeRota(self, ip): for linha in self.__listaRotas: if linha.getDestino() == ip: self.__listaRotas.remove(linha) return True else: return False "@param rota: default route" def setRotaDefault(self, rota): self.__default = rota def getRotaDefault(self): return self.__default
def run(self): """ Main part of the program. This is where it reads in and decodes all packet traffic :return: """ if os.name == "nt": socket_protocol = IPPROTO_IP else: socket_protocol = IPPROTO_ICMP sniffer = socket(AF_INET, SOCK_RAW, socket_protocol) sniffer.bind((self.host, 0)) sniffer.setsockopt(IPPROTO_IP, IP_HDRINCL, 1) try: while True: raw_buffer = sniffer.recvfrom(65565)[0] ip_header = IP(raw_buffer[0:20]) print("Protocol: %s %s -> %s" % (ip_header.protocol, ip_header.src_address, ip_header.dst_address)) if ip_header.protocol == "TCP": offset = ip_header.ihl * 4 buf = raw_buffer[offset:offset + ctypes.sizeof(TCP)] tcp_header = TCP(buf) bgp_dstport = self.unencrypted_comm(tcp_header.dstport) if bgp_dstport: self.bgp_dst = True print("TCP -> Source Port: %d Dest Port: %d" % (tcp_header.srcport, tcp_header.dstport)) except KeyboardInterrupt: exit()
def test_example_4_b(self): ip = IP('zazbz[bzb]cdb') self.assertTrue(ip.supports_ssl)
class StartMaker(): ip = IP() host = [] enlacePP = [] enlacePP = [] switch = [] router = [] nic_host = [] nic_switch = [] nic_router = [] # All Class Objects store in arrays[n] started 0 to n-1 # Start Hosts 0~11 for n in range(0,12): host.append(Host()) # Start Enlace 0~21 for n in range(0,22): enlacePP.append(EnlacePP()) # Start Switchs 0~2 for n in range(0,3): switch.append(Switch()) switch[0].setNome('switch_0') switch[1].setNome('Switch_1') switch[2].setNome('Switch_2') # Start Routers 0~2 for n in range(0,3): router.append(Router()) router[0].setNome('Router_0') router[1].setNome('Router_1') router[2].setNome('Router_2') # Start Hosts-NICs ( 12th ) # NIC receved MAC, Enlace and Host # Network 201.10.0.0 nic_host.append(NIC('01:0A:00:FF:0A:01',enlacePP[0],host[0])) nic_host.append(NIC('02:0A:00:FF:0A:02',enlacePP[1],host[1])) nic_host.append(NIC('03:0A:00:FF:0A:03',enlacePP[2],host[2])) nic_host.append(NIC('04:0A:00:FF:0A:04',enlacePP[3],host[3])) # Network 200.171.0.0 nic_host.append(NIC('05:0B:00:EE:0B:05',enlacePP[5],host[4])) nic_host.append(NIC('06:0B:00:EE:0B:06',enlacePP[6],host[5])) nic_host.append(NIC('07:0B:00:EE:0B:07',enlacePP[7],host[6])) nic_host.append(NIC('08:0B:00:EE:0B:08',enlacePP[8],host[7])) # Network 192.168.0.0 nic_host.append(NIC('09:0C:00:CC:0C:09',enlacePP[10],host[8])) nic_host.append(NIC('0A:0C:00:CC:0C:0A',enlacePP[11],host[9])) nic_host.append(NIC('0B:0C:00:CC:0C:0B',enlacePP[12],host[10])) nic_host.append(NIC('0C:0C:00:CC:0C:0C',enlacePP[13],host[11])) # Start Switchs-NICs ( 15th ) # Nic receved MAC, Enlace and Switch # Switch 0 nic_switch.append(NIC('040A7119SW01',enlacePP[0],switch[0])) nic_switch.append(NIC('040A7119SW02',enlacePP[1],switch[0])) nic_switch.append(NIC('040A7119SW03',enlacePP[2],switch[0])) nic_switch.append(NIC('040A7119SW04',enlacePP[3],switch[0])) # Dedicated Router 0 - Network 201.10.0.0 nic_switch.append(NIC('040A7119SW05',enlacePP[4],switch[0]))# Local Network 201.10.0.0 # Switch 1 nic_switch.append(NIC('040A7119SW06',enlacePP[5],switch[1])) nic_switch.append(NIC('040A7119SW07',enlacePP[6],switch[1])) nic_switch.append(NIC('040A7119SW08',enlacePP[7],switch[1])) nic_switch.append(NIC('040A7119SW09',enlacePP[8],switch[1])) # Dedicated Router 1 - Network 200.171.0.0 nic_switch.append(NIC('0040A7119SW10',enlacePP[9],switch[1]))# Local Network 200.171.0.0 # Switch 2 nic_switch.append(NIC('040A7119SW11',enlacePP[10],switch[2])) nic_switch.append(NIC('040A7119SW12',enlacePP[11],switch[2])) nic_switch.append(NIC('040A7119SW13',enlacePP[12],switch[2])) nic_switch.append(NIC('040A7119SW14',enlacePP[13],switch[2])) # Dedicated Router 2 - 192.168.0.0 nic_switch.append(NIC('040A7119SW15',enlacePP[14],switch[2]))# Local Network 192.168.0.0 # Start Routers-NICs ( 12th ) # Router 0 Networks 10.0.0.0 and 201.10.0.0 nic_router.append(NIC('040A7119SR01',enlacePP[4],router[0])) # Network 201.10.0.0 - Local nic_router.append(NIC('040A7119SR02',enlacePP[15],router[0])) # Network 10.0.0.0 nic_router.append(NIC('040A7119SR03',enlacePP[16],router[0])) # unused nic_router.append(NIC('040A7119SR04',enlacePP[17],router[0])) # unused # Router 1 Networks 10.0.0.0, 11.0.0.0 and 200.171.0.0 nic_router.append(NIC('040A7119SR05',enlacePP[15],router[1])) # Network 10.0.0.0 - 201.10.0.0 nic_router.append(NIC('040A7119SR06',enlacePP[18],router[1])) # Network 11.0.0.0 - 192.168.0.0 nic_router.append(NIC('040A7119SR07',enlacePP[9],router[1])) # Network 200.171.0.0 - Local nic_router.append(NIC('040A7119SR08',enlacePP[19],router[1])) # Internet # Router 2 Networks 11.0.0.0 and 192.168.0.0 nic_router.append(NIC('040A7119SR09',enlacePP[18],router[2])) # Network 11.0.0.0 nic_router.append(NIC('040A7119SR10',enlacePP[14],router[2])) # Network 192.168.0.0 - Local nic_router.append(NIC('040A7119SR11',enlacePP[20],router[2])) # unused nic_router.append(NIC('040A7119SR12',enlacePP[21],router[2])) # unused # Set Routers IP router[0].setIP('201.10.0.1') router[1].setIP('200.171.0.1') router[2].setIP('192.168.0.1') # Adding Routes #router.setRota(Rota('<destination>','<route>','<mask>', '<metric>', '<MAC>')) # Router 0 to Router 1 Network A router[0].setRota(Rota('201.10.0.0','201.10.0.1','255.255.0.0', '0', '040A7119SR01')) # Network 201.10.0.0 - Local router[0].setRota(Rota('200.171.0.0','200.171.0.1','255.255.0.0', '0', '040A7119SR02')) router[0].setRota(Rota('192.168.0.0','192.168.0.1','255.255.0.0', '0', '040A7119SR02')) router[0].setRota(Rota('10.0.0.0','10.0.0.1','255.0.0.0', '0', '040A7119SR02')) router[0].setRotaDefault(Rota('10.0.0.0','10.0.0.1','255.0.0.0', '0', '040A7119SR02')) # Router 1 Network 01, 02 and 04 router[1].setRota(Rota('200.171.0.0','200.171.0.1','255.255.0.0', '0', '040A7119SR07')) # Network 200.171.0.0 - Local router[1].setRota(Rota('201.10.0.0','201.10.0.1','255.255.0.0', '0', '040A7119SR05')) # Network 10.0.0.0 - 201.10.0.0 router[1].setRota(Rota('10.0.0.0','10.0.0.1','255.0.0.0', '0', '040A7119SR05')) # Network 10.0.0.0 - R05 router[1].setRota(Rota('192.168.0.0','192.168.0.1','255.255.0.0', '0', '040A7119SR06')) # Network 11.0.0.0 - 192.168.0.0 router[1].setRota(Rota('11.0.0.0','11.0.0.1','255.0.0.0', '0', '040A7119SR06')) # Network 11.0.0.0 - R06 router[1].setRotaDefault(Rota('0.0.0.0','0.0.0.0','0.0.0.0', '0', 'INTERNET')) # Router 2 Network 02 and 05 router[2].setRota(Rota('192.168.0.0','192.168.0.1','255.255.0.0', '0', '040A7119SR10')) # Network 192.168.0.0 - Local router[2].setRota(Rota('11.0.0.0','11.0.0.1','255.0.0.0', '0', '040A7119SR09')) router[2].setRota(Rota('200.171.0.0','200.171.0.1','255.255.0.0', '0', '040A7119SR09')) router[2].setRota(Rota('201.10.0.0','201.10.0.1','255.255.0.0', '0', '040A7119SR09')) router[2].setRotaDefault(Rota('11.0.0.0','11.0.0.1','255.0.0.0', '0', '040A7119SR09')) # HOSTs reset IPs# for n in range(0,12): host[n].setIP('ip-not-found') host[n].setMascara('255.255.0.0') host[n].setLigado(False) nic_host[n].setLigado(False) nic_host[n].setTDados(False) host[n].resetPing() # SWITCHs reset# switch[0].setLigado(False) for n in range(0,5): nic_switch[n].setLigado(False) nic_switch[n].setTDados(False) switch[1].setLigado(False) for n in range(5,10): nic_switch[n].setLigado(False) nic_switch[n].setTDados(False) switch[2].setLigado(False) for n in range(10,15): nic_switch[n].setLigado(False) nic_switch[n].setTDados(False) # ROUTERs # router[0].setLigado(False) for n in range(0,4): nic_router[n].setLigado(False) nic_router[n].setTDados(False) router[1].setLigado(False) for n in range(4,8): nic_router[n].setLigado(False) nic_router[n].setTDados(False) router[2].setLigado(False) for n in range(8,12): nic_router[n].setLigado(False) nic_router[n].setTDados(False)
def __init__(self): self.__ip = IP() self.__listaRotas = [] self.__default = None
class Router(EquipamentoRede): def __init__(self): self.__nome = "" EquipamentoRede.__init__(self) self.__tRotas = TabelaRotas() self.__IP = IP() self.__ICMP = ICMP(self) self.__ip = "" self.__mac = "" self.__novoQuadro = None self.__quadro = None def getIP(self): return self.__ip "@param ip: Router if address" def setIP(self, ip): self.__ip = ip def getMAC(self): return self.__mac "@param mac: Router mac address" def setMAC(self, mac): self.__mac = mac # Receive frame from NIC "@param quadro: frame received" "@param nic: Router NIC" def receberQuadro(self, quadro, nic): self.__quadro = quadro pacote = self.__quadro.getDados() pacPing = pacote.getDados() ip_pacote = pacote.getIPDestino() ttl = pacPing.getTtl() # Get route list lRotas = self.getRota() # Search for Router NIC source route in the route list for rota in lRotas: if rota.getIFace() == nic.getMac(): rota_local = rota mascara_local = rota.getMascara() ip_local = rota.getRoute() # Get the netip using destination frame ip netid_pacote = self.__IP.netID(ip_pacote, mascara_local) # Check if it's not in the local network and if it didn't come from itself # If didn't, it tries to find the destination route if netid_pacote != rota_local.getDestino() and self.__quadro.getOrigem() != nic.getMac(): # set router NIC source MAC self.setMAC(nic.getMac()) # Decrease TTL ttl = ttl - 1 pacPing.setTtl(ttl) # Search destination route rota_destino = self.__tRotas.encontrarRota(ip_pacote) # Frame ICMP-Solicita (ICMP-Request) if pacote.getIPDestino() == self.__ip and self.__quadro.getTipo() == 2 and pacPing.getCodigo() == 0: rota_reply = Rota(self.__IP.netID(self.getIP(), "255.255.255.0"),self.getIP(),"255.255.255.0", "0", nic.getMac()) self.enviarQuadro(self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()),rota_reply) # Send - PacotePing("reply",8) # Frame ICMP-Responde (ICMP-Answer) elif pacote.getIPDestino() == self.__ip and quadro.getTipo() == 2 and pacPing.getCodigo() == 8: rota_reply = Rota(self.__IP.netID(self.getIP(), "255.255.255.0"),self.getIP(),"255.255.255.0", "0", nic.getMac()) self.enviarQuadro(self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()),rota_reply) # Send - PacotePing("reply",8) # If destination was found elif rota_destino != None: # forwards self.enviarQuadro(self.__quadro, rota_destino) # Destination Host Unreachable elif ttl == 0: # Send ICMP-Responde (ICMP-Answer) rota_reply = Rota("127.0.0.0","127.0.0.1","255.255.255.0", "0", nic.getMac()) self.enviarQuadro(self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), ttl), rota_reply) # Simulating Internet else: if self.__tRotas.getRotaDefault().getIFace() == "INTERNET": rota_reply = Rota("127.0.0.0","127.0.0.1","255.255.255.0", "0", nic.getMac()) self.enviarQuadro(self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), 0), rota_reply) else: # Sending to default (next Router) self.enviarQuadro(self.__quadro, self.__tRotas.getRotaDefault()) # Frame ICMP-Solicita (ICMP-Request) elif pacote.getIPDestino() == self.__ip and self.__quadro.getTipo() == 2 and pacPing.getCodigo() == 0: rota_reply = Rota(self.__IP.netID(self.getIP(), "255.255.255.0"),self.getIP(),"255.255.255.0", "0", nic.getMac()) self.enviarQuadro(self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()),rota_reply) # Send - PacotePing("reply",8) "@param quadro: received frame" "@param rota: destination route" def enviarQuadro(self, quadro, rota): # Rebuiding the frame to forwards quadroRouter = self.constroiQuadro(quadro.getTamanho(), quadro.getDestino(), quadro.getDados()) quadroRouter.setTipo(quadro.getTipo()) # Find Router NIC to forwards the frame nicLista = self.getNicLista() nic_origem = None for nic in nicLista: if nic.getMac() == rota.getIFace(): nic_origem = nic # Change frame source MAC to Router nic MAC if nic_origem != None: quadroRouter.setOrigem(nic_origem.getMac()) nic_origem.recebeQuadro(quadroRouter) if nic_origem.enviaQuadroEnlace() == True: return True else: return False "@param tamanho: frame size" "@param destino: destination MAC" "@param pacote: Packet to be send" def constroiQuadro(self, tamanho, destino, pacote): self.__novoQuadro = Quadro(self.getMAC(), tamanho) self.__novoQuadro.setDados(pacote) self.__novoQuadro.setDestino(destino) return self.__novoQuadro "@param rota_def: router default route" def setRotaDefault(self, rota_def): self.__tRotas.setRotaDefault(rota_def) def getRotaDefault(self): return self.__tRotas.getRotaDefault() "@param rota: new route" def setRota(self, rota): self.__tRotas.addRota(rota) def getRota(self): return self.__tRotas.getLRotas() "@param nome: Router's name" def setNome(self, nome): self.__nome = nome def getNome(self): return self.__nome
def main(): """ Main part of the program. This is where it reads in and decodes all packet traffic :return: """ if name == "nt": socket_protocol = IPPROTO_IP else: socket_protocol = IPPROTO_ICMP sniffer = socket(AF_INET, SOCK_RAW, socket_protocol) sniffer.bind((host, 0)) sniffer.setsockopt(IPPROTO_IP, IP_HDRINCL, 1) if name == "nt": sniffer.ioctl(SIO_RCVALL, RCVALL_ON) try: while True: raw_buffer = sniffer.recvfrom(65565)[0] ip_header = IP(raw_buffer[0:20]) print("Protocol: %s %s -> %s" % (ip_header.protocol, ip_header.src_address, ip_header.dst_address)) if ip_header.protocol == "ICMP": offset = ip_header.ihl * 4 buf = raw_buffer[offset:offset + ctypes.sizeof(ICMP)] icmp_header = ICMP(buf) print("ICMP -> Type: %d Code: %d" % (icmp_header.type, icmp_header.code)) if ip_header.protocol == "TCP": offset = ip_header.ihl * 4 buf = raw_buffer[offset:offset + ctypes.sizeof(TCP)] tcp_header = TCP(buf) attack = unencrypted_comm(tcp_header.dstport) if attack: file = open('Attack_Packet.txt', 'w') file.write("Protocol: TCP") file.write("\tSource: %s" % ip_header.src_address) file.write("\tDestination Port: %s\n" % tcp_header.dstport) file.close() print("TCP -> Source Port: %d Dest Port: %d" % (tcp_header.srcport, tcp_header.dstport)) if ip_header.protocol == "UDP": offset = ip_header.ihl * 4 buf = raw_buffer[offset:offset + ctypes.sizeof(UDP)] udp_header = UDP(buf) attack = unencrypted_comm(udp_header.dstport) if attack: file = open('Attack_Packet.txt', 'w') file.write("Protocol: TCP") file.write("\tSource: %s" % ip_header.src_address) file.write("\tDestination Port: %s\n" % tcp_header.dstport) file.close() print("UDP -> Source Port: %d Dest Port: %d" % (udp_header.srcport, udp_header.dstport)) except KeyboardInterrupt: if name == "nt": sniffer.ioctl(SIO_RCVALL, RCVALL_OFF)
def test_example_2(self): ip = IP('abcd[bddb]xyyx') self.assertFalse(ip.supports_tls)
def test_example_3(self): ip = IP('aaaa[qwer]tyui') self.assertFalse(ip.supports_tls)
def test_example_4(self): ip = IP('ioxxoj[asdfgh]zxcvbn') self.assertTrue(ip.supports_tls)
def test_example_1_b(self): ip = IP('aba[bab]xyz') self.assertTrue(ip.supports_ssl)
class Router(EquipamentoRede): def __init__(self): self.__nome = "" EquipamentoRede.__init__(self) self.__tRotas = TabelaRotas() self.__IP = IP() self.__ICMP = ICMP(self) self.__ip = "" self.__mac = "" self.__novoQuadro = None self.__quadro = None def getIP(self): return self.__ip "@param ip: Router if address" def setIP(self, ip): self.__ip = ip def getMAC(self): return self.__mac "@param mac: Router mac address" def setMAC(self, mac): self.__mac = mac # Receive frame from NIC "@param quadro: frame received" "@param nic: Router NIC" def receberQuadro(self, quadro, nic): self.__quadro = quadro pacote = self.__quadro.getDados() pacPing = pacote.getDados() ip_pacote = pacote.getIPDestino() ttl = pacPing.getTtl() # Get route list lRotas = self.getRota() # Search for Router NIC source route in the route list for rota in lRotas: if rota.getIFace() == nic.getMac(): rota_local = rota mascara_local = rota.getMascara() ip_local = rota.getRoute() # Get the netip using destination frame ip netid_pacote = self.__IP.netID(ip_pacote, mascara_local) # Check if it's not in the local network and if it didn't come from itself # If didn't, it tries to find the destination route if netid_pacote != rota_local.getDestino() and self.__quadro.getOrigem( ) != nic.getMac(): # set router NIC source MAC self.setMAC(nic.getMac()) # Decrease TTL ttl = ttl - 1 pacPing.setTtl(ttl) # Search destination route rota_destino = self.__tRotas.encontrarRota(ip_pacote) # Frame ICMP-Solicita (ICMP-Request) if pacote.getIPDestino() == self.__ip and self.__quadro.getTipo( ) == 2 and pacPing.getCodigo() == 0: rota_reply = Rota( self.__IP.netID(self.getIP(), "255.255.255.0"), self.getIP(), "255.255.255.0", "0", nic.getMac()) self.enviarQuadro( self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()), rota_reply) # Send - PacotePing("reply",8) # Frame ICMP-Responde (ICMP-Answer) elif pacote.getIPDestino() == self.__ip and quadro.getTipo( ) == 2 and pacPing.getCodigo() == 8: rota_reply = Rota( self.__IP.netID(self.getIP(), "255.255.255.0"), self.getIP(), "255.255.255.0", "0", nic.getMac()) self.enviarQuadro( self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()), rota_reply) # Send - PacotePing("reply",8) # If destination was found elif rota_destino != None: # forwards self.enviarQuadro(self.__quadro, rota_destino) # Destination Host Unreachable elif ttl == 0: # Send ICMP-Responde (ICMP-Answer) rota_reply = Rota("127.0.0.0", "127.0.0.1", "255.255.255.0", "0", nic.getMac()) self.enviarQuadro( self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), ttl), rota_reply) # Simulating Internet else: if self.__tRotas.getRotaDefault().getIFace() == "INTERNET": rota_reply = Rota("127.0.0.0", "127.0.0.1", "255.255.255.0", "0", nic.getMac()) self.enviarQuadro( self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), 0), rota_reply) else: # Sending to default (next Router) self.enviarQuadro(self.__quadro, self.__tRotas.getRotaDefault()) # Frame ICMP-Solicita (ICMP-Request) elif pacote.getIPDestino() == self.__ip and self.__quadro.getTipo( ) == 2 and pacPing.getCodigo() == 0: rota_reply = Rota(self.__IP.netID(self.getIP(), "255.255.255.0"), self.getIP(), "255.255.255.0", "0", nic.getMac()) self.enviarQuadro( self.__ICMP.respondeICMP(pacote.getIPOrigem(), self.__quadro.getOrigem(), pacPing.getTtl()), rota_reply) # Send - PacotePing("reply",8) "@param quadro: received frame" "@param rota: destination route" def enviarQuadro(self, quadro, rota): # Rebuiding the frame to forwards quadroRouter = self.constroiQuadro(quadro.getTamanho(), quadro.getDestino(), quadro.getDados()) quadroRouter.setTipo(quadro.getTipo()) # Find Router NIC to forwards the frame nicLista = self.getNicLista() nic_origem = None for nic in nicLista: if nic.getMac() == rota.getIFace(): nic_origem = nic # Change frame source MAC to Router nic MAC if nic_origem != None: quadroRouter.setOrigem(nic_origem.getMac()) nic_origem.recebeQuadro(quadroRouter) if nic_origem.enviaQuadroEnlace() == True: return True else: return False "@param tamanho: frame size" "@param destino: destination MAC" "@param pacote: Packet to be send" def constroiQuadro(self, tamanho, destino, pacote): self.__novoQuadro = Quadro(self.getMAC(), tamanho) self.__novoQuadro.setDados(pacote) self.__novoQuadro.setDestino(destino) return self.__novoQuadro "@param rota_def: router default route" def setRotaDefault(self, rota_def): self.__tRotas.setRotaDefault(rota_def) def getRotaDefault(self): return self.__tRotas.getRotaDefault() "@param rota: new route" def setRota(self, rota): self.__tRotas.addRota(rota) def getRota(self): return self.__tRotas.getLRotas() "@param nome: Router's name" def setNome(self, nome): self.__nome = nome def getNome(self): return self.__nome
def test_example_3_b(self): ip = IP('aaa[kek]eke') self.assertTrue(ip.supports_ssl)
def test_example_2_b(self): ip = IP('xyx[xyx]xyxz') self.assertFalse(ip.supports_ssl)
def test_example_1(self): ip = IP('abba[mnop]qrst') self.assertTrue(ip.supports_tls)
from math import pow from VLSM import VLSM from auxiliares import MSR,getIP,getDeptos from IP import IP #Limpia la pantalla clear = lambda: os.system('cls') #Windows # clear = lambda: os.system('cls') #Linux #Obtiene IP valida inicial #ip = getIP() #Obtiene departamentos deptos = getDeptos() #################r### ip = IP() V = VLSM(deptos,ip) ip_s = V.autoIP() ip = IP(ip_s) print ip_s if ip.validar() is True: V.setIP(ip) else: exit() #IP valida para numero de hosts dados Vvalido = V.validar()