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

Class Net

scapy/base_classes.py:160–316  ·  view source on GitHub ↗

Network object from an IP address or hostname and mask Examples: - With mask:: >>> list(Net("192.168.0.1/24")) ['192.168.0.0', '192.168.0.1', ..., '192.168.0.255'] - With 'end':: >>> list(Net("192.168.0.100", "192.168.0.200"))

Source from the content-addressed store, hash-verified

158
159
160class Net(Gen[str]):
161 """
162 Network object from an IP address or hostname and mask
163
164 Examples:
165
166 - With mask::
167
168 >>> list(Net("192.168.0.1/24"))
169 ['192.168.0.0', '192.168.0.1', ..., '192.168.0.255']
170
171 - With 'end'::
172
173 >>> list(Net("192.168.0.100", "192.168.0.200"))
174 ['192.168.0.100', '192.168.0.101', ..., '192.168.0.200']
175
176 - With 'scope' (for multicast)::
177
178 >>> Net("224.0.0.1%lo")
179 >>> Net("224.0.0.1", scope=conf.iface)
180 """
181 name = "Net" # type: str
182 family = socket.AF_INET # type: int
183 max_mask = 32 # type: int
184
185 @classmethod
186 def name2addr(cls, name):
187 # type: (str) -> str
188 try:
189 return next(
190 addr_port[0]
191 for family, _, _, _, addr_port in
192 socket.getaddrinfo(name, None, cls.family)
193 if family == cls.family
194 )
195 except socket.error:
196 if re.search("(^|\\.)[0-9]+-[0-9]+($|\\.)", name) is not None:
197 raise Scapy_Exception("Ranges are no longer accepted in %s()" %
198 cls.__name__)
199 raise
200
201 @classmethod
202 def ip2int(cls, addr):
203 # type: (str) -> int
204 return cast(int, struct.unpack(
205 "!I", socket.inet_aton(cls.name2addr(addr))
206 )[0])
207
208 @staticmethod
209 def int2ip(val):
210 # type: (int) -> str
211 return socket.inet_ntoa(struct.pack('!I', val))
212
213 def __init__(self, net, stop=None, scope=None):
214 # type: (str, Optional[str], Optional[str]) -> None
215 if "*" in net:
216 raise Scapy_Exception("Wildcards are no longer accepted in %s()" %
217 self.__class__.__name__)

Callers 14

__init__Method · 0.90
h2iMethod · 0.90
parse_argsMethod · 0.90
parse_optionsMethod · 0.90
parse_optionsMethod · 0.90
parse_argsMethod · 0.90
__init__Method · 0.90
arpcachepoisonFunction · 0.90
parse_optionsMethod · 0.90
parse_optionsMethod · 0.90
parse_argsMethod · 0.90
parse_argsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected