arptools

CLI tools to do network analysis with ARP packets.

__author__: str = 'Stefano Cuizza'

The package author(s).

__version__: str = '0.1.1'

The package version.

arp_announcement(mapping: tuple[str, str], ethernet_src: str | None = None, ethernet_dst: str | None = None, count: int = 0, interval: float = 1.0, verbose: int | None = None) None[source]

Sends and ARP announcement advertising the given MAC/IP mapping.

Parameters:
  • mapping (tuple[str, str]) – a MAC/IP pair.

  • ethernet_src (Optional[str]) – the source MAC address of the Ethernet frame.

  • ethernet_dst (Optional[str]) – the destination MAC address of the Ethernet frame.

  • count (int) – how many packet to send.

  • interval (float) – time interval between packets (only used when count is 0).

  • verbose (Optional[int]) – verbosity level.

Return type:

None

arp_probe(target_ip: str, count: int = 0, interval: float = 1.0, quit_on_first_reply: bool = False, timeout: int | None = None, verbose: int | None = None) None[source]

Sends an ARP probe to the specified target.

Parameters:
  • target_ip (str) – the destination IP.

  • count (int) – how many packet to send.

  • interval (float) – time interval between packets (only used when count is 0).

  • quit_on_first_reply (bool) – sends packets until it gets a reply.

  • timeout (Optional[int]) – how long to wait for a reply.

  • verbose (Optional[int]) – verbosity level.

Return type:

None

arp_pscan(target_range: str, ttl: int = 300) None[source]

Performs a passive scan of the network by extracting MAC/IP pairs from broadcast ARP requests.

Parameters:
  • target_range (str) – the target IP range, in CIDR notation.

  • ttl (int) – initial time to live for a new mapping, in seconds.

Return type:

None

arp_reply(target_ip: str, ethernet_src: str | None = None, ethernet_dst: str | None = None, arp_hwsrc: str | None = None, arp_psrc: str | None = None, count: int = 0, interval: float = 1.0, verbose: int | None = None, prn: ~collections.abc.Callable[[~scapy.plist.QueryAnswer], str | None] = <function _prn>, prnfail: ~collections.abc.Callable[[~scapy.packet.Packet | ~scapy.plist.PacketList | ~scapy.plist.SndRcvList], str | None] = <function _prnfail>) None[source]

Sends an ARP reply packet.

Parameters:
  • target_ip (str) – the target IP of the ARP reply.

  • ethernet_src (Optional[str]) – the source MAC address of the Ethernet frame.

  • ethernet_dst (Optional[str]) – the destination MAC address of the Ethernet frame.

  • arp_hwsrc (Optional[str]) – the hardware source address of the ARP packet.

  • arp_psrc (Optional[str]) – the protocol source address of the ARP packet.

  • count (int) – how many packet to send.

  • interval (float) – time interval between packets (only used when count is 0).

  • verbose (Optional[int]) – verbosity level.

  • prn (Callable[[QueryAnswer], str | None]) – function used to print packets that have received an answer.

  • prnfail (Callable[[Packet | PacketList | SndRcvList], str | None]) – function used to print packets that have not received an answer.

Return type:

None

arp_request(target_ip: str, ethernet_src: str | None = None, ethernet_dst: str | None = None, arp_hwsrc: str | None = None, arp_psrc: str | None = None, count: int = 0, interval: float = 1.0, quit_on_first_reply: bool = False, timeout: int | None = None, ignore_unanswered: bool = False, verbose: int | None = None, prn: ~collections.abc.Callable[[~scapy.plist.QueryAnswer], str | None] = <function _prn>, prn_qofr: ~collections.abc.Callable[[~scapy.plist.QueryAnswer], None] = <function _prn_qofr>, prnfail: ~collections.abc.Callable[[~scapy.packet.Packet | ~scapy.plist.PacketList | ~scapy.plist.SndRcvList], str | None] = <function _prnfail>) None[source]

Sends an ARP request packet.

Parameters:
  • target_ip (str) – the target IP of the ARP request.

  • ethernet_src (Optional[str]) – the source MAC address of the Ethernet frame.

  • ethernet_dst (Optional[str]) – the destination MAC address of the Ethernet frame.

  • arp_hwsrc (Optional[str]) – the hardware source address of the ARP packet.

  • arp_psrc (Optional[str]) – the protocol source address of the ARP packet.

  • count (int) – how many packet to send.

  • interval (float) – time interval between packets (only used when count is 0).

  • quit_on_first_reply (bool) – sends packets until it gets a reply.

  • timeout (Optional[int]) – how long to wait for a reply.

  • ignore_unanswered (bool) – whether to print unanswered packets.

  • verbose (Optional[int]) – verbosity level.

  • prn (Callable[[QueryAnswer], str | None]) – function used to print packets that have received an answer.

  • prn_qofr (Callable[[QueryAnswer], None]) – function used to print packets that have received an answer when quit_on_first_reply is True.

  • prnfail (Callable[[Packet | PacketList | SndRcvList], str | None]) – function used to print packets that have not received an answer.

Return type:

None

arp_scan(target_range: str, use_arp_probes: bool = False, timeout: int = 2, verbose: int | None = None) None[source]

Performs an ARP scan of the network by sending ARP requests to all the IPs in range and waiting for a response.

Parameters:
  • target_range (str) – target IP range in CIDR notation (e.g. 192.168.1.0/24).

  • use_arp_probes (bool) – whether to use ARP probes to scan the network.

  • timeout (int) – how long to wait for a reply.

  • verbose (Optional[int]) – verbosity level.

Return type:

None