MCPcopy Index your code
hub / github.com/secdev/scapy / ScopedIP

Function ScopedIP

scapy/base_classes.py:128–157  ·  view source on GitHub ↗

An str that also holds extra attributes. Examples:: >>> ScopedIP("224.0.0.1%eth0") # interface 'eth0' >>> ScopedIP("224.0.0.1%1") # interface index 1 >>> ScopedIP("224.0.0.1", scope=conf.iface)

(net: str, scope: Optional[Any] = None)

Source from the content-addressed store, hash-verified

126
127
128def ScopedIP(net: str, scope: Optional[Any] = None) -> _ScopedIP:
129 """
130 An str that also holds extra attributes.
131
132 Examples::
133
134 >>> ScopedIP("224.0.0.1%eth0") # interface 'eth0'
135 >>> ScopedIP("224.0.0.1%1") # interface index 1
136 >>> ScopedIP("224.0.0.1", scope=conf.iface)
137 """
138 if "%" in net:
139 try:
140 net, scope = net.split("%", 1)
141 except ValueError:
142 raise Scapy_Exception("Scope identifier can only be present once !")
143 if scope is not None:
144 from scapy.interfaces import resolve_iface, network_name, dev_from_index
145 try:
146 iface = dev_from_index(int(scope))
147 except (ValueError, TypeError):
148 iface = resolve_iface(scope)
149 if not iface.is_valid():
150 raise Scapy_Exception(
151 "RFC6874 scope identifier '%s' could not be resolved to a "
152 "valid interface !" % scope
153 )
154 scope = network_name(iface)
155 x = _ScopedIP(net)
156 x.scope = scope
157 return x
158
159
160class Net(Gen[str]):

Callers 6

h2iMethod · 0.90
h2iMethod · 0.90
dnssdFunction · 0.90
__init__Method · 0.85
__iter__Method · 0.85
choiceMethod · 0.85

Calls 6

Scapy_ExceptionClass · 0.90
dev_from_indexFunction · 0.90
resolve_ifaceFunction · 0.90
network_nameFunction · 0.90
_ScopedIPClass · 0.85
is_validMethod · 0.80

Tested by

no test coverage detected