Utility functions for IPv6.
- class scapy.utils6.Net6(net: str, stop: Optional[str] = None)
Network object from an IP address or hostname and mask
- family: int = 10
- static int2ip(val: int) str
- classmethod ip2int(addr: str) int
- max_mask: int = 128
- name: str = 'Net6'
- net: Union[None, str]
- scapy.utils6.construct_source_candidate_set(addr: str, plen: int, laddr: Iterator[Tuple[str, int, str]]) List[str]
Given all addresses assigned to a specific interface (‘laddr’ parameter), this function returns the “candidate set” associated with ‘addr/plen’.
Basically, the function filters all interface addresses to keep only those that have the same scope as provided prefix.
This is on this list of addresses that the source selection mechanism will then be performed to select the best source address associated with some specific destination that uses this prefix.
- scapy.utils6.get_source_addr_from_candidate_set(dst: str, candidate_set: List[str]) str
This function implement a limited version of source address selection algorithm defined in section 5 of RFC 3484. The format is very different from that described in the document because it operates on a set of candidate source address for some specific route.
- scapy.utils6.in6_6to4ExtractAddr(addr: str) Optional[str]
Extract IPv4 address embedded in 6to4 address. Passed address must be a 6to4 address. None is returned on error.
- scapy.utils6.in6_addrtomac(addr: str) Optional[str]
Extract the mac address from provided address. None is returned on error.
- scapy.utils6.in6_addrtovendor(addr: str) Optional[str]
Extract the MAC address from a modified EUI-64 constructed IPv6 address provided and use the IANA oui.txt file to get the vendor. The database used for the conversion is the one loaded by Scapy from a Wireshark installation if discovered in a well-known location. None is returned on error, “UNKNOWN” if the vendor is unknown.
- scapy.utils6.in6_and(a1: bytes, a2: bytes) bytes
Provides a bit to bit AND of provided addresses. They must be passed in network format. Return value is also an IPv6 address in network format.
- scapy.utils6.in6_cidr2mask(m: int) bytes
Return the mask (bitstring) associated with provided length value. For instance if function is called on 48, return value is b’ÿÿÿÿÿÿ'.
- scapy.utils6.in6_ctop(addr: str) Optional[str]
Convert an IPv6 address in Compact Representation Notation (RFC 1924) to printable representation ;-) Returns None on error.
- scapy.utils6.in6_get6to4Prefix(addr: str) Optional[str]
Returns the /48 6to4 prefix associated with provided IPv4 address On error, None is returned. No check is performed on public/private status of the address
- scapy.utils6.in6_getAddrType(addr: str) int
- scapy.utils6.in6_getLinkScopedMcastAddr(addr: str, grpid: Optional[Union[bytes, str, int]] = None, scope: int = 2) Optional[str]
Generate a Link-Scoped Multicast Address as described in RFC 4489. Returned value is in printable notation.
‘addr’ parameter specifies the link-local address to use for generating Link-scoped multicast address IID.
By default, the function returns a ::/96 prefix (aka last 32 bits of returned address are null). If a group id is provided through ‘grpid’ parameter, last 32 bits of the address are set to that value (accepted formats : b’4Vx’ or ‘12345678’ or 0x12345678 or 305419896).
By default, generated address scope is Link-Local (2). That value can be modified by passing a specific ‘scope’ value as an argument of the function. RFC 4489 only authorizes scope values <= 2. Enforcement is performed by the function (None will be returned).
If no link-local address can be used to generate the Link-Scoped IPv6 Multicast address, or if another error occurs, None is returned.
- scapy.utils6.in6_getLocalUniquePrefix() str
Returns a pseudo-randomly generated Local Unique prefix. Function follows recommendation of Section 3.2.2 of RFC 4193 for prefix generation.
- scapy.utils6.in6_getRandomizedIfaceId(ifaceid: str, previous: Optional[str] = None) Tuple[str, str]
Implements the interface ID generation algorithm described in RFC 3041. The function takes the Modified EUI-64 interface identifier generated as described in RFC 4291 and an optional previous history value (the first element of the output of this function). If no previous interface identifier is provided, a random one is generated. The function returns a tuple containing the randomized interface identifier and the history value (for possible future use). Input and output values are provided in a “printable” format as depicted below.
>>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3') ('4c61:76ff:f46a:a5f3', 'd006:d540:db11:b092') >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3', previous='d006:d540:db11:b092') ('fe97:46fe:9871:bd38', 'eeed:d79c:2e3f:62e')
- scapy.utils6.in6_get_common_plen(a: str, b: str) int
Return common prefix length of IPv6 addresses a and b.
- scapy.utils6.in6_getha(prefix: str) str
Return the anycast address associated with all home agents on a given subnet.
- scapy.utils6.in6_getnsma(a: bytes) bytes
Return link-local solicited-node multicast address for given address. Passed address must be provided in network format. Returned value is also in network format.
- scapy.utils6.in6_getnsmac(a: bytes) str
Return the multicast mac address associated with provided IPv6 address. Passed address must be in network format.
- scapy.utils6.in6_getscope(addr: str) int
Returns the scope of the address.
- scapy.utils6.in6_ifaceidtomac(ifaceid_s: str) Optional[str]
Extract the mac address from provided iface ID. Iface ID is provided in printable format (“XXXX:XXFF:FEXX:XXXX”, eventually compressed). None is returned on error.
- scapy.utils6.in6_isaddr6to4(x: str) bool
Return True if provided address (in printable format) is a 6to4 address (being in 2002::/16).
- scapy.utils6.in6_isaddrTeredo(x: str) bool
Return True if provided address is a Teredo, meaning it is under the /32 conf.teredoPrefix prefix value (by default, 2001::). Otherwise, False is returned. Address must be passed in printable format.
- scapy.utils6.in6_isaddrllallnodes(str: str) bool
Returns True if address is the link-local all-nodes multicast address (ff02::1).
- scapy.utils6.in6_isaddrllallservers(str: str) bool
Returns True if address is the link-local all-servers multicast address (ff02::2).
- scapy.utils6.in6_isanycast(x: str) bool
- scapy.utils6.in6_isdocaddr(str: str) bool
Returns True if provided address in printable format belongs to 2001:db8::/32 address space reserved for documentation (as defined in RFC 3849).
- scapy.utils6.in6_iseui64(x: str) bool
Return True if provided address has an interface identifier part created in modified EUI-64 format (meaning it matches
*::*:*ff:fe*:*). Otherwise, False is returned. Address must be passed in printable format.
- scapy.utils6.in6_isgladdr(str: str) bool
Returns True if provided address in printable format belongs to _allocated_ global address space (2000::/3). Please note that, Unique Local addresses (FC00::/7) are not part of global address space, and won’t match.
- scapy.utils6.in6_isincluded(addr: str, prefix: str, plen: int) bool
Returns True when ‘addr’ belongs to prefix/plen. False otherwise.
- scapy.utils6.in6_islladdr(str: str) bool
Returns True if provided address in printable format belongs to _allocated_ link-local unicast address space (fe80::/10)
- scapy.utils6.in6_isllsnmaddr(str: str) bool
Return True if provided address is a link-local solicited node multicast address, i.e. belongs to ff02::1:ff00:0/104. False is returned otherwise.
- scapy.utils6.in6_ismaddr(str: str) bool
Returns True if provided address in printable format belongs to allocated Multicast address space (ff00::/8).
- scapy.utils6.in6_ismgladdr(str: str) bool
Returns True if address belongs to global multicast address space (ff0e::/16).
- scapy.utils6.in6_ismlladdr(str: str) bool
Returns True if address belongs to link-local multicast address space (ff02::/16)
- scapy.utils6.in6_ismnladdr(str: str) bool
Returns True if address belongs to node-local multicast address space (ff01::/16) as defined in RFC
- scapy.utils6.in6_ismsladdr(str: str) bool
Returns True if address belongs to site-local multicast address space (ff05::/16). Site local address space has been deprecated. Function remains for historic reasons.
- scapy.utils6.in6_issladdr(str: str) bool
Returns True if provided address in printable format belongs to _allocated_ site-local address space (fec0::/10). This prefix has been deprecated, address being now reserved by IANA. Function will remain for historic reasons.
- scapy.utils6.in6_isuladdr(str: str) bool
Returns True if provided address in printable format belongs to Unique local address space (fc00::/7).
- scapy.utils6.in6_isvalid(address: str) bool
Return True if ‘address’ is a valid IPv6 address string, False otherwise.
- scapy.utils6.in6_mactoifaceid(mac: str, ulbit: Optional[int] = None) str
Compute the interface ID in modified EUI-64 format associated to the Ethernet address provided as input. value taken by U/L bit in the interface identifier is basically the reversed value of that in given MAC address it can be forced to a specific value by using optional ‘ulbit’ parameter.
- scapy.utils6.in6_or(a1: bytes, a2: bytes) bytes
Provides a bit to bit OR of provided addresses. They must be passed in network format. Return value is also an IPv6 address in network format.
- scapy.utils6.in6_ptoc(addr: str) Optional[str]
Converts an IPv6 address in printable representation to RFC 1924 Compact Representation ;-) Returns None on error.
- scapy.utils6.in6_ptop(str: str) str
Normalizes IPv6 addresses provided in printable format, returning the same address in printable format. (2001:0db8:0:0::1 -> 2001:db8::1)
- scapy.utils6.in6_xor(a1: bytes, a2: bytes) bytes
Provides a bit to bit XOR of provided addresses. They must be passed in network format. Return value is also an IPv6 address in network format.
- scapy.utils6.teredoAddrExtractInfo(x: str) Tuple[str, int, str, int]
Extract information from a Teredo address. Return value is a 4-tuple made of IPv4 address of Teredo server, flag value (int), mapped address (non obfuscated) and mapped port (non obfuscated). No specific checks are performed on passed address.