LocalResolver (version 1.0.0)
index
localresolver.py

This module implements local hostname resolver tool with scapy.
 
Useful wireshark filter:
 - udp.port == 53 || udp.port == 5355 || udp.port == 5353 || udp.port == 137
 
Linux tools/services to resolve hostname:
~# sudo apt install samba
~# sudo nano /etc/samba/smb.conf
[global]
   netbios name = MYHOST
   workgroup = MYGROUP
   wins support = yes
   name resolve order = lmhosts wins bcast host
~# sudo apt install avahi-daemon  # MDNS
~# sudo apt install systemd-resolved # LLMNR
~# sudo nano /etc/systemd/resolved.conf
LLMNR=yes
~# sudo systemctl restart winbind
~# sudo systemctl restart systemd-resolved
~# sudo systemctl start nmbd
~# sudo systemctl start avahi-daemon
~# sudo responder -I eth0
~#

 
Classes
       
builtins.object
LocalResolver
Result

 
class LocalResolver(builtins.object)
    LocalResolver(name: str = None, ip: str = None, retry: int = 2, inter: int = 1, timeout: int = 3)
 
This class resolve hostname using Netbios, LLMNR, MDNS and DNS.
 
  Methods defined here:
__init__(self, name: str = None, ip: str = None, retry: int = 2, inter: int = 1, timeout: int = 3)
Initialize self.  See help(type(self)) for accurate signature.
parse_dns_ip_response(self, packet: 'Packet') -> str
This method parses DNS response and returns name.
parse_dns_name_response(self, packet: 'Packet') -> str
This method parses DNS response and returns IP address.
parse_llmnr_ip_response(self, packet: 'Packet') -> str
This method parses LLMNR response and returns name.
parse_llmnr_name_response(self, packet: 'Packet') -> str
This method parses LLMNR response and returns IP address.
parse_mdns_ip_response(self, packet: 'Packet') -> str
This method parses MDNS response and returns name.
parse_mdns_name_response(self, packet: 'Packet') -> str
This method parses MDNS response and returns IP address.
parse_netbios_ip_response(self, packet: 'Packet') -> str
This method parses netbios response and returns name.
parse_netbios_name_response(self, packet: 'Packet') -> str
This method parses netbios response and returns IP address.
redirect(self, packet: 'Packet') -> None
This function calls callbacks for sniffed packets.
resolve_dns_ip(self, callback: collections.abc.Callable = None) -> None
This function sends the DNS queries
requests to get name from IP address.
resolve_dns_name(self, callback: collections.abc.Callable = None) -> None
This function sends the DNS queries
requests to get IP address from name.
resolve_llmnr_ip(self, callback: collections.abc.Callable = None) -> None
This function sends the LLMNR queries
requests to get hostname from IP address.
resolve_llmnr_name(self, callback: collections.abc.Callable = None) -> None
This function sends the LLMNR queries
requests to get IP address from hostname.
resolve_mdns_ip(self, callback: collections.abc.Callable = None) -> None
This function sends the MDNS queries
requests to get name from IP address.
resolve_mdns_name(self, callback: collections.abc.Callable = None) -> None
This function sends the MDNS queries
requests to get IP address from name.
resolve_netbios_ip(self, callback: collections.abc.Callable = None) -> None
This function sends the Netbios queries
requests to get hostname from IP address.
resolve_netbios_name(self, callback: collections.abc.Callable = None) -> None
This function sends the Netbios queries
requests to get IP address from hostname.
sender(self, packet: 'Packet') -> str
This function sends a query.
sniff(self) -> None
This function starts sniffer.
wait_threads(self) -> None
This method waits all LocalResolver threads.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Result(builtins.object)
    Result(source: str, ip: str, hostname: str, type_: str) -> None
 
Result(source: str, ip: str, hostname: str, type_: str)
 
  Methods defined here:
__eq__(self, other)
Return self==value.
__hash__(self)
Return hash(self).
__init__(self, source: str, ip: str, hostname: str, type_: str) -> None
Initialize self.  See help(type(self)) for accurate signature.
__repr__(self)
Return repr(self).

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'hostname': <class 'str'>, 'ip': <class 'str'>, 'source': <class 'str'>, 'type_': <class 'str'>}
__dataclass_fields__ = {'hostname': Field(name='hostname',type=<class 'str'>,default...appingproxy({}),kw_only=False,_field_type=_FIELD), 'ip': Field(name='ip',type=<class 'str'>,default=<data...appingproxy({}),kw_only=False,_field_type=_FIELD), 'source': Field(name='source',type=<class 'str'>,default=<...appingproxy({}),kw_only=False,_field_type=_FIELD), 'type_': Field(name='type_',type=<class 'str'>,default=<d...appingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__match_args__ = ('source', 'ip', 'hostname', 'type_')

 
Functions
       
netbios_decode(encoded_name: str) -> str
This function encodes name in Netbios encoding.
 
>>> netbios_decode('EGFCEFEECACACACACACACACACACACACA')
'FRED'
>>> netbios_decode('CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
'*'
>>>
netbios_encode(name: str) -> str
This function encodes name in Netbios encoding.
 
>>> netbios_encode('FRED')
'EGFCEFEECACACACACACACACACACACACA'
>>> netbios_encode('*')
'CKCACACACACACACACACACACACACACACA'
>>>
resolve_local_ip(ip: str, retry: int = 2, inter: int = 1, timeout: int = 3, netbios: bool = True, llmnr: bool = True, mdns: bool = True, dns: bool = True) -> Iterable[LocalResolver.Result]
This function use LocalResolver
to get hostname from IP address.
resolve_local_name(hostname: str, retry: int = 2, inter: int = 1, timeout: int = 3, netbios: bool = True, llmnr: bool = True, mdns: bool = True, dns: bool = True) -> Iterable[LocalResolver.Result]
This function use LocalResolver
to get IP address from hostname.

 
Data
        __all__ = ['LocalResolver', 'resolve_local_ip', 'resolve_local_name', 'Result', 'netbios_encode', 'netbios_decode']
__annotations__ = {'is_windows': <class 'bool'>}
__author_email__ = 'mauricelambert434@gmail.com'
__copyright__ = '\nLocalResolver Copyright (C) 2021, 2023 Mauric...ome to redistribute it\nunder certain conditions.\n'
__description__ = 'This package implements local hostname resolver tool with scapy.'
__license__ = 'GPL-3.0 License'
__maintainer__ = 'Maurice Lambert'
__maintainer_email__ = 'mauricelambert434@gmail.com'
__url__ = 'https://github.com/mauricelambert/LocalResolver/'

 
Author
        Maurice Lambert