Beispiel #1
0
def selectInterface():
    if os.name=='nt':
        counter = 0
        arrInterfaces = get_windows_if_list()
        for arrInt in arrInterfaces:
            sIPv4 = ''
            for sIP in arrInt['ips']:
                if len(sIP.split('.')) == 4: sIPv4 = sIP
            print('['+str(counter)+'] ' + sIPv4 + ': ' + arrInt['name'] + ' (' + arrInt['description'] + ')')
            arrInterfaces[counter] = arrInterfaces[counter]['name']
            counter += 1
    else:
        counter = 0
        arrInterfaces = get_if_list()
        for sInt in arrInterfaces:
            if not sInt == 'lo':
                print('[' + str(counter) + ']: ' + sInt)
                counter += 1
            else:
                arrInterfaces.remove(sInt)
        if(len(arrInterfaces)==1): return arrInterfaces[0]
    print('[Q] Quit')
    sAnsw = input('Select interface [0]: ')
    if sAnsw.lower()[0] == 'q': exit()
    if sAnsw == '' or not sAnsw.isdigit(): sAnsw = '0'
    return arrInterfaces[int(sAnsw)]
Beispiel #2
0
def get_ifaces() -> List[Dict]:
    """Get network interface list."""
    if sys.platform == "win32":
        from scapy.all import get_windows_if_list
        return get_windows_if_list()

    from scapy.all import get_if_list
    return get_if_list()
Beispiel #3
0
def network_interfaces():
    network_interface_name = []
    network_interface_description = []

    for network_interface in get_windows_if_list():
        network_interface_name.append(network_interface['name'])
        network_interface_description.append(network_interface['description'])

    return network_interface_name, network_interface_description
Beispiel #4
0
def get_interface_names():
    int_names = ""
    if platform.system() == "Windows":
        int_names = scapy.get_windows_if_list()
    # for ethName in interface_list:
    #     if not ethName['name'] == "":
    #         print(ethName["name"])

    if platform.system() == "Linux":
        int_names = scapy.get_if_list()

    return int_names
Beispiel #5
0
def list_eth_interfaces():
    '''
    Returns a list of all Ethernet interfaces and MAC addresses.
    '''
    result = {}
    if os.name == 'nt':
        ifs = sca.get_windows_if_list()
        for interface in ifs:
            result[interface['description']] = interface['name']
    else:
        result = sca.get_if_list()

    return result
def main():
    interfaces = get_windows_if_list()
    localsDictio = {}
    localsIpList = []
    for key, _ in enumerate(interfaces):
        name = interfaces[key]['name']
        mac = interfaces[key]['mac']
        print("{}, mac: {}, found:".format(name, mac))
        try:
            locals = arp_scanner(name)
            localsDictio[name] = locals
            localsIpList = [ip for locals in list(localsDictio.values()) for ip in locals]
        except KeyboardInterrupt:
            print("CTRL+C pressed. Exiting. ")
            continue
    return localsIpList
Beispiel #7
0
def list_eth_interfaces():
    """
    Construct a list of all available Ethernet interfaces.

    Returns:
        A dictionary of Ethernet interfaces.
        Keys are human-readable names.
        Values are ID-strings suitable for passing to ScaPy.
        (Formatting of the ID-strings is OS-specific)
    """
    result = {}
    if os.name == 'nt':
        ifs = sca.get_windows_if_list()
        for interface in ifs:
            result[interface['description']] = interface['name']
    else:
        ifs = sca.get_if_list()
        for interface in ifs:
            result[interface] = interface
    return result
Beispiel #8
0
def listEthernetCard():
    netcard_info = []
    if os.name == 'nt':

        #windows下用psutil获取的网卡不对
        from scapy.all import get_windows_if_list
        interfaces = get_windows_if_list()
        for i in interfaces:
            netcard_info.append(i['name'])
        return netcard_info

    # 获取Linux所有网卡信息
    info = psutil.net_if_addrs()
    for k, v in info.items():
        for item in v:

            # 去掉本地回环
            if item[0] == 2 and not item[1] == '127.0.0.1':
                netcard_info.append(k)

    # 返回信息像这样:
    # [('wlp2s0', '192.168.1.110')]
    return netcard_info
Beispiel #9
0
def get_iface():
    if platform.system() == 'Windows':
        from scapy.all import get_windows_if_list, get_if_list

        winList = get_windows_if_list()
        intfList = get_if_list()

        # Pull guids and names from the windows list
        guidToNameDict = {e["guid"]: e["name"] for e in winList}

        # Extract the guids from the interface list
        guidsFromIntfList = [(e.split("_"))[1] for e in intfList]

        # Using the interface list of guids, pull the names from the
        # Windows map of guids to names
        namesAllowedList = [guidToNameDict.get(e) for e in guidsFromIntfList]

        return namesAllowedList

    elif platform.system() == "Linux":
        iface = subprocess.check_output(
            ["bash", "-c", "route | grep default | awk '{print $8}'"])

        return iface.decode("utf-8")[:-1:]
Beispiel #10
0
def func_interfaces():
    winList = get_windows_if_list()
    if len(winList):
        title = '{:>62}'.format('Windows Interface(s)')
        title_header = '\t{:^30}   {:^24}   {:^30}'.format(
            'Name', 'MAC', 'Description')
        title_line = '\t{:>30}   {:>24}   {:>30}'.format(
            '-' * 30, '-' * 24, '-' * 30)
        print()
        print(title)
        print()
        print(title_header)
        print(title_line)
        for winMac in winList:
            tmp_write = '\t{:<30}   {:^24}   {:<30}'.format(
                winMac['name'], winMac['mac'], winMac['description'])
            print(tmp_write)
    else:
        title = '{:>62}'.format('Windows Interface(s)')
        text_tmp = '\tNo interfaces were found!'
        print()
        print(title)
        print()
        print(text_tmp)
def find_guid_from_host_name(host_name):
    for devinfo in get_windows_if_list():
        if devinfo['name'] == host_name:
            return devinfo['guid']
import netifaces as ni
from pprint import pformat
from scapy.all import get_windows_if_list

iface_lists = [i['name'] for i in get_windows_if_list()]
#print(pformat(iface_lists))

test_host_name = 'Intel(R) Ethernet Connection I217-LM'


def find_guid_from_host_name(host_name):
    for devinfo in get_windows_if_list():
        if devinfo['name'] == host_name:
            return devinfo['guid']


my_guid = find_guid_from_host_name(test_host_name)

ip, netmask, broadcast = ni.ifaddresses(my_guid)[2][0].values()

print("HostName: {}".format(test_host_name))
print("GUID: {}".format(my_guid))
print("IP = {}".format(ip))
print("netmask = {}".format(netmask))
Beispiel #13
0
def main():
    init_log(level=logging.DEBUG)
    log = logging.getLogger('main')
    log.info("Traffic Manager starts")
    parser = argparse.ArgumentParser(description='RCC Traffic Manager')
    parser.add_argument('-r',
                        '--rx_port',
                        type=int,
                        action='store',
                        default=50000,
                        help='rx port for the communication with the RCC')
    parser.add_argument('-t',
                        '--tx_port',
                        type=int,
                        action='store',
                        default=50001,
                        help='tx port for the communication with the RCC')
    parser.add_argument('-f',
                        '--filter',
                        type=str,
                        action='store',
                        default="dst='192.168.137.*'",
                        help='Filetr. Set the remote network filter')
    parser.add_argument('-i',
                        '--iface',
                        type=str,
                        action='store',
                        default="eth1",
                        help='The locaal interface to use')
    parser.add_argument('-l',
                        '--list',
                        action='store_true',
                        help='Show interface list')

    args = parser.parse_args(
        argv[1:]
    )  # ('-r 50000 -t 50001 -f dst="192.168.4.*" -i USB' ).split())

    if args.list == True:
        #  from scapy.all import get_if_list
        if os.name == 'nt':
            from scapy.all import get_windows_if_list
            list = get_windows_if_list()
            for iface in list:
                print('%s %s' % (iface["description"], iface["ips"]))
                pass
        else:
            from scapy.all import get_if_list
            list = get_if_list()
            for iface in list:
                print(iface)
        exit(0)

    tm = TrafficManager(iface=args.iface,
                        filter=args.filter,
                        rx_port=args.rx_port,
                        tx_port=args.tx_port)
    tm.start()
    log.info("Traffic Manager active")

    while (True):
        sleep(10)
    log.info("Traffic Manager exit")
Beispiel #14
0
 def __init__(self):
     super().__init__()
     self.ifaces_list_all = Scapy.get_windows_if_list()
     self.ifaces_name_list = [ item['name'] for item in self.ifaces_list_all ]
     self.initUI()
Beispiel #15
0
import sys
from scapy.all import conf, get_if_hwaddr

if sys.platform.startswith('win'):
    from scapy.all import get_windows_if_list
    interfaces = get_windows_if_list()
    windows = True
else:
    from scapy.all import get_if_list
    interfaces = get_if_list()
    windows = False


def get_ifaces():
    """Get a list of network interfces.
    Returns a list like this:

    {'eth0': {'index': 0,
              'inet': None,
              'inet6': None,
              'mac': '80:fa:5b:4b:f9:18',
              'name': 'eth0'},
     'lo': {'index': 1,
            'inet': '127.0.0.1',
            'inet6': '::1',
            'mac': '00:00:00:00:00:00',
            'name': 'lo'},
     'vboxnet0': {'index': 3,
                  'inet': '192.168.56.1',
                  'inet6': 'fe80::800:27ff:fe00:0',
                  'mac': '0a:00:27:00:00:00',
Beispiel #16
0
 def set_Initial_Iface(self, text):
     self.iface_choose = text
     self.iface_list_all = Scapy.get_windows_if_list()
     iface_names = [item['name'] for item in self.iface_list_all]
     self.central_Widget.Set_Iface_Comb(iface_names, text)