Beispiel #1
0
def _parse_connected_clients_list(contents):
    regex = "<form(?:.+?)<tr(?:.+?)<tr bgcolor=(?:.+?)<font size=2>(.+?)</td><td><font size=2>(.+?)</td><td><font size=2>([0-9]+)</td>"
    regex_dhcp_list = re.compile(regex, re.DOTALL)

    lst = ConnectedClientsList()

    for id, match_groups in enumerate(re.findall(regex_dhcp_list, contents), start=1):
        ip, mac, lease_time = match_groups

        if not validator.is_valid_ip_address(ip):
            raise RouterParseError("Invalid IP address: %s" % ip)

        if not validator.is_valid_mac_address(mac):
            raise RouterParseError("Invalid MAC address: %s" % mac)

        lease_time = int(lease_time)

        item = ConnectedClientsListItem()
        item.set_client_name("Client %d" % id)
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)

        item.set_lease_time(lease_time)

        lst.append(item)

    return lst
Beispiel #2
0
def _parse_connected_clients_list(contents):
    regex = "<form(?:.+?)<tr(?:.+?)<tr bgcolor=(?:.+?)<font size=2>(.+?)</td><td><font size=2>(.+?)</td><td><font size=2>([0-9]+)</td>"
    regex_dhcp_list = re.compile(regex, re.DOTALL)

    lst = ConnectedClientsList()

    for id, match_groups in enumerate(re.findall(regex_dhcp_list, contents),
                                      start=1):
        ip, mac, lease_time = match_groups

        if not validator.is_valid_ip_address(ip):
            raise RouterParseError("Invalid IP address: %s" % ip)

        if not validator.is_valid_mac_address(mac):
            raise RouterParseError("Invalid MAC address: %s" % mac)

        lease_time = int(lease_time)

        item = ConnectedClientsListItem()
        item.set_client_name("Client %d" % id)
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)

        item.set_lease_time(lease_time)

        lst.append(item)

    return lst
Beispiel #3
0
def _parse_mac_address(html):
    match_object = re.compile("dw\(MACAddress\)(?:.+?)table2(?:.+?)>&nbsp;(.+?)\s", re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine mac address')

    mac = match_object.group(1).strip(" ")
    if not validator.is_valid_mac_address(mac):
        raise RouterParseError('Found an invalid MAC address: %s' % mac)

    return converter.normalize_mac(mac)
Beispiel #4
0
def _parse_mac_address(html):
    match_object = re.compile("dw\(MACAddress\)(?:.+?)table2(?:.+?)>&nbsp;(.+?)\s", re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine mac address')

    mac = match_object.group(1).strip(" ")
    if not validator.is_valid_mac_address(mac):
        raise RouterParseError('Found an invalid MAC address: %s' % mac)

    return converter.normalize_mac(mac)
Beispiel #5
0
def _parse_mac_address(contents):
    regex = "bssid_drv\[0\] ='((?:(?:[a-f0-9]{2}:){5})(?:[a-f0-9]{2}))';"
    regex_mac_address = re.compile(regex, re.DOTALL)

    match_object = regex_mac_address.search(contents)

    if match_object is None:
        raise RouterParseError("Cannot _parse mac address from contents")

    mac = match_object.group(1).strip(" ")
    if not validator.is_valid_mac_address(mac):
        raise RouterParseError("Found an invalid MAC address: %s" % mac)

    return converter.normalize_mac(mac)
Beispiel #6
0
def _parse_mac_address(contents):
    regex = "bssid_drv\[0\] ='((?:(?:[a-f0-9]{2}:){5})(?:[a-f0-9]{2}))';"
    regex_mac_address = re.compile(regex, re.DOTALL)

    match_object = regex_mac_address.search(contents)

    if match_object is None:
        raise RouterParseError("Cannot _parse mac address from contents")

    mac = match_object.group(1).strip(" ")
    if not validator.is_valid_mac_address(mac):
        raise RouterParseError("Found an invalid MAC address: %s" % mac)

    return converter.normalize_mac(mac)
Beispiel #7
0
def _parse_connected_clients_list(html):
    dhcp_list = re.compile('var dhcpList=new Array\((.*)\);').search(html)
    if dhcp_list is None:
        raise RouterParseError('Cannot find DHCP list.')
    dhcp_list = dhcp_list.group(1)

    results = re.compile("'(.+?);(.+?);(.+?);[01];(\d+)'").findall(dhcp_list)
    lst = ConnectedClientsList()
    for client_name, ip, mac, lease_time in results:
        if not validator.is_valid_ip_address(ip):
            raise RouterParseError('Invalid IP address: %s' % ip)
        if not validator.is_valid_mac_address(mac):
            raise RouterParseError('Invalid MAC address: %s' % mac)

        item = ConnectedClientsListItem()
        item.set_client_name(client_name)
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_lease_time(int(lease_time))

        lst.append(item)

    return lst
Beispiel #8
0
def _parse_connected_clients_list(html):
    regex_dhcp_list = "<tr class=table2 align=center><td><font size=2>(.+?)</td><td><font size=2>(.+?)</td>"
    lst = ConnectedClientsList()

    for id, (ip, mac) in enumerate(re.findall(regex_dhcp_list, html), start=1):
        if ip == "None":
            # this entry is added when there are no connected clients
            break

        if not validator.is_valid_ip_address(ip):
            raise RouterParseError('Invalid IP address: %s' % ip)

        if not validator.is_valid_mac_address(mac):
            raise RouterParseError('Invalid MAC address: %s' % mac)

        item = ConnectedClientsListItem()
        item.set_client_name('Client %d' % id)
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_lease_time(0)

        lst.append(item)

    return lst
Beispiel #9
0
def _parse_connected_clients_list(html):
    regex_dhcp_list = "<tr class=table2 align=center><td><font size=2>(.+?)</td><td><font size=2>(.+?)</td>"
    lst = ConnectedClientsList()

    for id, (ip, mac) in enumerate(re.findall(regex_dhcp_list, html), start=1):
        if ip == "None":
            # this entry is added when there are no connected clients
            break

        if not validator.is_valid_ip_address(ip):
            raise RouterParseError('Invalid IP address: %s' % ip)

        if not validator.is_valid_mac_address(mac):
            raise RouterParseError('Invalid MAC address: %s' % mac)

        item = ConnectedClientsListItem()
        item.set_client_name('Client %d' % id)
        item.set_mac(converter.normalize_mac(mac))
        item.set_ip(ip)
        item.set_lease_time(0)

        lst.append(item)

    return lst