示例#1
0
	def initialize(self):
		if self.subnet:
			address_range = self.get_address_range(self.subnet)
			print('Size of network: ' + str(address_range.size()))
			self.alive_hosts = self.get_alive_hosts(address_range)

			for counter, ip in enumerate(self.alive_hosts):
				host = Host()
				host.ip = ip
				host.id += str(counter)
				self.host_list.append(host)

		else:
			host = Host()
			host.ip = self.address
			self.add_host(host)
示例#2
0
	def get_arp_cache(self, host):
		"""Get ARP table from host"""

		results = Crawler.snmp.walk(host.ip, '.1.3.6.1.2.1.4.22.1.2.' + str(host.interface))

		if results is not None:
			for result in results:
				for name, val in result:
					print(str(name) + ' = ' + hex_to_mac(val))
					if str(name).find('1.3.6.1.2.1.4.22.1.2.' + str(host.interface)) != -1:
						new_host = Host()
						new_host.ip = str(name).split('1.3.6.1.2.1.4.22.1.2.' + str(host.interface) + '.',1)[1]
						#print('new host ip: ' + new_host.ip)
						new_host.mac = hex_to_mac(val)
						#print('new host mac: ' + new_host.mac)

						self.add_host(new_host)
示例#3
0
	def create_host(self, ip_addr):
		"""Create a new host"""

		#print('CREATING NEW HOST WITH IP ' + str(ip_addr))

		if self.ip_exists(ip_addr):
			#print('\tIP ALREADY EXISTS')
			return self.get_host_by_ip(ip_addr)

		new_host = Host()
		new_host.id += str(self.host_counter)
		new_host.ip = ip_addr
		new_host.add_ip(ip_addr)

		self.host_counter += 1

		self.all_hosts.append(new_host)
		self.add_to_host_list(new_host)

		return new_host
示例#4
0
	def get_neighbors(self, host):	#needs more testing
		"""Get list of host neighbors using Cisco Discovery Protocol"""

		print('Getting neighbors')
		neighbors = []
		host.visited = True

		results = Crawler.snmp.walk(host.ip, self.oid.neighbors2)

		if results is None:
			return []

		for result in results:
			for name, val in result:
				new_host = Host()
				new_host.ip = hex_to_ip(val)
				new_host.id = self.get_host_id((new_host.ip))
				if new_host.id is not None:
					neighbors.append(new_host.id)

		return neighbors
示例#5
0
文件: test.py 项目: Evnsan/MAC0448
elementos = []

# __      __      __
#|  |    |  |    |  |
#|  |----|  |----|  |
#|--|    |--|    |--|
# h0      r0      h1

rotas ={'10.0.0.0': '0', '10.1.1.0': '1'}



#Rede
#-hosts
h0 = Host("h0")
h0.ip = '10.0.0.1'
h0.setPapel('ircc')
h0
h1 = Host("h1")
h1.ip = '10.1.1.1'
h1.setPapel('ircc')
h1
#-roteadores
r0 = Router("r0", 2)
ipRouter = ['0', '10.0.0.2','1','10.1.1.2', '2' , '192.168.3.3']
r0.setIp(ipRouter)
r0
#-enlaces
e0 = Enlace(h0, r0.getPorta(0), "10M", "5s")
e1 = Enlace(h1, r0.getPorta(1), "10M", "5s")
#e1 = Enlace(h0, h1, "10M", "5s")