pwnlib.util.net — Networking interfaces

pwnlib.util.net.getifaddrs() dict list[source]

A wrapper for libc’s getifaddrs.

Parameters

None

Returns

list of dictionaries each representing a struct ifaddrs. The dictionaries have the fields name, flags, family, addr and netmask. Refer to getifaddrs(3) for details. The fields addr and netmask are themselves dictionaries. Their structure depend on family. If family is not socket.AF_INET or socket.AF_INET6 they will be empty.

pwnlib.util.net.interfaces(all=False) dict[source]
Parameters
  • all (bool) – Whether to include interfaces with not associated address.

  • DefaultFalse.

Returns

A dictionary mapping each of the hosts interfaces to a list of it’s addresses. Each entry in the list is a tuple (family, addr), and family is either socket.AF_INET or socket.AF_INET6.

pwnlib.util.net.interfaces4(all=False) dict[source]

As interfaces() but only includes IPv4 addresses and the lists in the dictionary only contains the addresses not the family.

Parameters
  • all (bool) – Whether to include interfaces with not associated address.

  • DefaultFalse.

Returns

A dictionary mapping each of the hosts interfaces to a list of it’s IPv4 addresses.

Examples

>>> interfaces4(all=True) 
{...'127.0.0.1'...}
pwnlib.util.net.interfaces6(all=False) dict[source]

As interfaces() but only includes IPv6 addresses and the lists in the dictionary only contains the addresses not the family.

Parameters
  • all (bool) – Whether to include interfaces with not associated address.

  • DefaultFalse.

Returns

A dictionary mapping each of the hosts interfaces to a list of it’s IPv6 addresses.

Examples

>>> interfaces6() 
{...'::1'...}
pwnlib.util.net.sockaddr(host, port, network='ipv4')[source]

Creates a sockaddr_in or sockaddr_in6 memory buffer for use in shellcode.

Parameters
  • host (str) – Either an IP address or a hostname to be looked up.

  • port (int) – TCP/UDP port.

  • network (str) – Either ‘ipv4’ or ‘ipv6’.

Returns

A tuple containing the sockaddr buffer, length, and the address family.