def ifconfig(): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interfaces = ifdata.interfaces total_interfaces_info = [] for interface in interfaces: ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interface_instance = ifdata.get_interface(interface) interface_values = interface_instance.get_values() interface_dict = {'name': interface, 'info': interface_values} total_interfaces_info.append(interface_dict) response = jsonify(total_interfaces_info) return response
def get_interface(name): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) try: interface_instance = ifdata.get_interface(name) interface_values = interface_instance.get_values() interface_dict = {'name': name, 'info': interface_values} except InterfaceNotFound: interface_dict = { 'response': "Can't find this interface", 'status': 'error' } response = jsonify(interface_dict) return response
def delete_network_interfaces(): """Delete network interfaces This function performs a clean up for the following network interfaces virbr[1-4] """ # elevate module re-launches the current process with root/admin privileges # using one of the following mechanisms : sudo (Linux, macOS) # becoming in root elevate(graphical=False) ifdata = Ifcfg(subprocess.check_output(['ifconfig', '-a'])) for interface in range(1, 5): current_interface = 'virbr{}'.format(interface) if current_interface in ifdata.interfaces: # the network interface exists net_object = ifdata.get_interface(current_interface) net_up = net_object.get_values().get('UP') net_running = net_object.get_values().get('RUNNING') if net_up or net_running: # the network interface is up or running try: # down and delete the network interface ifconfig.Interface(current_interface).down() brctl.Bridge(current_interface).delete() except IOError: LOG.warn('[Errno 19] No such device: {}'.format( current_interface)) # adding the network interface try: brctl.addbr(current_interface) except IOError: LOG.warn('[Errno 17] File exists {}'.format(current_interface))
def get_InfoInterface(self, req, eth, **_kwargs): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interface = ifdata.get_interface(eth) body = json.dumps(interface.get_values()) return Response(content_type='application/json', body=body)
from scapy.all import * import commands from ifparser import Ifcfg def MAC_parser(host): os.popen('ping -c 1 %s' % host) fields = os.popen('grep "%s " /proc/net/arp' % host).read().split() if len(fields) == 6 and fields[3] != "00:00:00:00:00:00": return fields[3] else: print 'no response from', host victim_ip = raw_input("Input victim_ip : ") ifdata = Ifcfg(commands.getoutput('ifconfig -a')) ifdata.interfaces eth0 = ifdata.get_interface('eth0') eth0.BROADCAST mac_add = eth0.hwaddr ip_add = netinfo.get_ip('eth0') strs = subprocess.check_output(shlex.split('ip r l')) match_string = r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' gateway = re.search('default via ' + match_string, strs).group(1) print "ip_add : "+ip_add print "mac_add : "+mac_add print "gateway : "+gateway if os.geteuid() != 0: sys.exit("*** Please run as root ***") victim_MAC = MAC_parser(victim_ip) print "victim_MAC : "+victim_MAC gateway_MAC = MAC_parser(gateway) print 'gateway_MAC : ' + gateway_MAC
def mac_parser(host): os.popoen('ping 1 %s' % host) fileds = os.popen('grep %s /proc/net/arp' % host).read().split() if len(fields) == 6 and fields[3] != "00:00:00:00:00:00": return fields[3] else: print ' ***** use sudo plz *****' ,host vic_ip = raw_input("plz write victim's ip :") data = Ifcfg(commands.getoutput('ifconfig -a')) data.interfaces enp0s3 = data.get_interface('enp0s3') enp0s3.BROADCAST add_mac = enp0s3.hwaddr add_ip = netinfo.get_ip('enp0s3') strs = subprocess.check_output(shlex.split('ip r l')) string_match = r'(\d{1,3}\.\d{1.3}\.\d{1.3}\.\d{1.3})' gateway = re.search('default via ' + string_match, strs) print "add_ip : "+add_ip print "add_mac : "+add_mac print "geteway : "+gateway