Example #1
0
	def _gen_mac_addrs(self):
		self._mac_addrs = Queue()
		base = "00:00:c0:a8:7b:{:02x}"
		num = 2
		for x in xrange(50):
			new_mac = base.format(num+x)
			ip = ".".join(map(lambda x: str(int(x, 16)), new_mac.split(":")[2:]))
			# just testing this out...
			sh.arp("-s", ip, new_mac)
			self._mac_addrs.put(new_mac)
Example #2
0
	def _gen_mac_addrs(self):
		self._mac_addrs = Queue()
		base = "00:00:c0:a8:7b:{:02x}"
		num = 2
		for x in xrange(50):
			new_mac = base.format(num+x)
			ip = ".".join(map(lambda x: str(int(x, 16)), new_mac.split(":")[2:]))
			# just testing this out...
			sh.arp("-s", ip, new_mac)
			self._mac_addrs.put(new_mac)
Example #3
0
def flush(ip=None, interface=None):
    if not ip:
        table = _load_mac_table()
        entries = table.get(interface, []) if interface else itertools.chain(*table.values())
    else:
        entries = [(ip, None)]

    for ip, _ in entries:
        sh.arp('-d', ip)
        logging.info('Flushed %s' % ip)
Example #4
0
def flush(ip=None, interface=None):
    if not ip:
        table = _load_mac_table()
        entries = table.get(interface, []) if interface else itertools.chain(
            *table.values())
    else:
        entries = [(ip, None)]

    for ip, _ in entries:
        sh.arp('-d', ip)
        logging.info('Flushed %s' % ip)
Example #5
0
def scan(allowed):
	output = arp('-n').strip().split('\n')

	good = {}
	bad = {}

	for line in output:
		ip, hwtype, mac, flags, iface = tuple(re.split('\s\s+', line.lower()))
		
		if ip == 'address':
			continue

		#print("Found %s with %s on %s" % (mac, ip, iface))
		
		if mac in allowed:
			good[mac] = ip
		else:
			bad[mac] = ip
	
	print("Good answers:")
	
	for mac, ip in good.items():
		print("%s: (%s)" % (mac, good[mac]))

	print("\n\nBAD ANSWERS:")
	for mac, ip in bad.items():
		print("%s (%s)" % (mac, ip))
Example #6
0
def scan(allowed):
    output = arp('-n').strip().split('\n')

    good = {}
    bad = {}

    for line in output:
        ip, hwtype, mac, flags, iface = tuple(re.split('\s\s+', line.lower()))

        if ip == 'address':
            continue

        #print("Found %s with %s on %s" % (mac, ip, iface))

        if mac in allowed:
            good[mac] = ip
        else:
            bad[mac] = ip

    print("Good answers:")

    for mac, ip in good.items():
        print("%s: (%s)" % (mac, good[mac]))

    print("\n\nBAD ANSWERS:")
    for mac, ip in bad.items():
        print("%s (%s)" % (mac, ip))
Example #7
0
def _load_mac_table():
    pattern = re.compile(r' \((\d+\.\d+\.\d+.\d+)\) at ([0-9a-f:]{17}) \[[\w]+\] on (\w+)')

    results = {}
    for line in sh.arp('-a'):
        match = pattern.search(line)
        if not match:
            continue

        ip, mac, interface = match.group(1), match.group(2), match.group(3)
        if interface not in results:
            results[interface] = list()
        results[interface].append((ip, mac))

    return results
Example #8
0
def _load_mac_table():
    pattern = re.compile(
        r' \((\d+\.\d+\.\d+.\d+)\) at ([0-9a-f:]{17}) \[[\w]+\] on (\w+)')

    results = {}
    for line in sh.arp('-a'):
        match = pattern.search(line)
        if not match:
            continue

        ip, mac, interface = match.group(1), match.group(2), match.group(3)
        if interface not in results:
            results[interface] = list()
        results[interface].append((ip, mac))

    return results
Example #9
0
    def _vm_ip_address(self):
        """Return the ip address (on the host) of the VM being handled
        :returns: IP Address, or None if it does not yet have one
        """
        domain = self._libvirt_domain()
        if domain is None:
            return None

        info = xmltodict.parse(domain.XMLDesc())
        mac_addr = self._mac_addr = info["domain"]["devices"]["interface"]["mac"]["@address"]
        output = arp("-a", "-n")
        for line in output.split("\n"):
            if mac_addr in line:
                ip_address = re.search(r'(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})', line)
                return ip_address.group(1)

        return None
Example #10
0
def arp_dump():
    '''[Internal] Uses arp -a to dump mac adresses
    Returns a dict {mac:ip,...}'''
    dump = arp("-a")
    lines = dump.strip().split('\n')
    ret = {}
    for line in lines:
        split = line.strip().split(' ')
        ip = split[1][1:-1]
        mac = split[3]
        if split[4] == 'on':
            iface = split[5]
        else:
            iface = split[6]
        if iface == INTERFACE:
            ret[mac] = ip
    return ret
Example #11
0
    def _vm_ip_address(self):
        """Return the ip address (on the host) of the VM being handled
        :returns: IP Address, or None if it does not yet have one
        """
        domain = self._libvirt_domain()
        if domain is None:
            return None

        info = xmltodict.parse(domain.XMLDesc())
        mac_addr = self._mac_addr = info["domain"]["devices"]["interface"]["mac"]["@address"]
        output = arp("-a", "-n")
        for line in output.split("\n"):
            if mac_addr in line:
                ip_address = re.search(r'(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})', line)
                return ip_address.group(1)

        return None
def main(echo, fetch_title, hello, arp):
    if echo:
        print("Your message:", echo)
    if fetch_title:
        titles = re.findall("<title>(.*?)</title>",
                            str(urlopen(fetch_title).read()),
                            re.IGNORECASE | re.MULTILINE)
        if titles:
            print(titles[0])
        else:
            print("No title found.")
    if hello:
        print("mymodule.hello =", h)
    if arp:
        print(sh.arp("-a").rstrip())
    if not (echo or fetch_title or arp or hello):
        print("You didn't specify any options. Use --help to get help.")