Utility functions for IPv6.
- class scapy.utils6.Net6(net, stop=None)
Network object from an IP address or hostname and mask
- family = 10
- static int2ip(val)
- classmethod ip2int(addr)
- max_mask = 128
- name = 'Net6'
- scapy.utils6.construct_source_candidate_set(addr, plen, laddr)
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, candidate_set)
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.
Extract IPv4 address embedded in 6to4 address. Passed address must be a 6to4 address. None is returned on error.
Extract the mac address from provided address. None is returned on error.
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, a2)
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.
Return the mask (bitstring) associated with provided length value. For instance if function is called on 48, return value is b’ÿÿÿÿÿÿ'.
Convert an IPv6 address in Compact Representation Notation (RFC 1924) to printable representation ;-) Returns None on error.
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_getLinkScopedMcastAddr(addr, grpid=None, scope=2)
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.
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, previous=None)
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, b)
Return common prefix length of IPv6 addresses a and b.
Return the anycast address associated with all home agents on a given subnet.
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.
Return the multicast mac address associated with provided IPv6 address. Passed address must be in network format.
Returns the scope of the address.
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.
Return True if provided address (in printable format) is a 6to4 address (being in 2002::/16).
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.
Returns True if address is the link-local all-nodes multicast address (ff02::1).
Returns True if address is the link-local all-servers multicast address (ff02::2).
Returns True if provided address in printable format belongs to 2001:db8::/32 address space reserved for documentation (as defined in RFC 3849).
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.
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, prefix, plen)
Returns True when ‘addr’ belongs to prefix/plen. False otherwise.
Returns True if provided address in printable format belongs to _allocated_ link-local unicast address space (fe80::/10)
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.
Returns True if provided address in printable format belongs to allocated Multicast address space (ff00::/8).
Returns True if address belongs to global multicast address space (ff0e::/16).
Returns True if address belongs to link-local multicast address space (ff02::/16)
Returns True if address belongs to node-local multicast address space (ff01::/16) as defined in RFC
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.
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.
Returns True if provided address in printable format belongs to Unique local address space (fc00::/7).
Return True if ‘address’ is a valid IPv6 address string, False otherwise.
- scapy.utils6.in6_mactoifaceid(mac, ulbit=None)
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, a2)
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.
Converts an IPv6 address in printable representation to RFC 1924 Compact Representation ;-) Returns None on error.
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, a2)
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.
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.