repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
secdev/scapy | scapy/utils.py | get_temp_file | def get_temp_file(keep=False, autoext="", fd=False):
"""Creates a temporary file.
:param keep: If False, automatically delete the file when Scapy exits.
:param autoext: Suffix to add to the generated file name.
:param fd: If True, this returns a file-like object with the temporary
file o... | python | def get_temp_file(keep=False, autoext="", fd=False):
"""Creates a temporary file.
:param keep: If False, automatically delete the file when Scapy exits.
:param autoext: Suffix to add to the generated file name.
:param fd: If True, this returns a file-like object with the temporary
file o... | [
"def",
"get_temp_file",
"(",
"keep",
"=",
"False",
",",
"autoext",
"=",
"\"\"",
",",
"fd",
"=",
"False",
")",
":",
"f",
"=",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"prefix",
"=",
"\"scapy\"",
",",
"suffix",
"=",
"autoext",
",",
"delete",
"=",
"Fal... | Creates a temporary file.
:param keep: If False, automatically delete the file when Scapy exits.
:param autoext: Suffix to add to the generated file name.
:param fd: If True, this returns a file-like object with the temporary
file opened. If False (default), this returns a file path. | [
"Creates",
"a",
"temporary",
"file",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L51-L69 | train |
secdev/scapy | scapy/utils.py | get_temp_dir | def get_temp_dir(keep=False):
"""Creates a temporary file, and returns its name.
:param keep: If False (default), the directory will be recursively
deleted when Scapy exits.
:return: A full path to a temporary directory.
"""
dname = tempfile.mkdtemp(prefix="scapy")
if not kee... | python | def get_temp_dir(keep=False):
"""Creates a temporary file, and returns its name.
:param keep: If False (default), the directory will be recursively
deleted when Scapy exits.
:return: A full path to a temporary directory.
"""
dname = tempfile.mkdtemp(prefix="scapy")
if not kee... | [
"def",
"get_temp_dir",
"(",
"keep",
"=",
"False",
")",
":",
"dname",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"prefix",
"=",
"\"scapy\"",
")",
"if",
"not",
"keep",
":",
"conf",
".",
"temp_files",
".",
"append",
"(",
"dname",
")",
"return",
"dname"
] | Creates a temporary file, and returns its name.
:param keep: If False (default), the directory will be recursively
deleted when Scapy exits.
:return: A full path to a temporary directory. | [
"Creates",
"a",
"temporary",
"file",
"and",
"returns",
"its",
"name",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L72-L85 | train |
secdev/scapy | scapy/utils.py | restart | def restart():
"""Restarts scapy"""
if not conf.interactive or not os.path.isfile(sys.argv[0]):
raise OSError("Scapy was not started from console")
if WINDOWS:
try:
res_code = subprocess.call([sys.executable] + sys.argv)
except KeyboardInterrupt:
res_code = 1
... | python | def restart():
"""Restarts scapy"""
if not conf.interactive or not os.path.isfile(sys.argv[0]):
raise OSError("Scapy was not started from console")
if WINDOWS:
try:
res_code = subprocess.call([sys.executable] + sys.argv)
except KeyboardInterrupt:
res_code = 1
... | [
"def",
"restart",
"(",
")",
":",
"if",
"not",
"conf",
".",
"interactive",
"or",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"sys",
".",
"argv",
"[",
"0",
"]",
")",
":",
"raise",
"OSError",
"(",
"\"Scapy was not started from console\"",
")",
"if",
"WI... | Restarts scapy | [
"Restarts",
"scapy"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L111-L122 | train |
secdev/scapy | scapy/utils.py | hexdump | def hexdump(x, dump=False):
"""Build a tcpdump like hexadecimal view
:param x: a Packet
:param dump: define if the result must be printed or returned in a variable
:returns: a String only when dump=True
"""
s = ""
x = bytes_encode(x)
x_len = len(x)
i = 0
while i < x_len:
... | python | def hexdump(x, dump=False):
"""Build a tcpdump like hexadecimal view
:param x: a Packet
:param dump: define if the result must be printed or returned in a variable
:returns: a String only when dump=True
"""
s = ""
x = bytes_encode(x)
x_len = len(x)
i = 0
while i < x_len:
... | [
"def",
"hexdump",
"(",
"x",
",",
"dump",
"=",
"False",
")",
":",
"s",
"=",
"\"\"",
"x",
"=",
"bytes_encode",
"(",
"x",
")",
"x_len",
"=",
"len",
"(",
"x",
")",
"i",
"=",
"0",
"while",
"i",
"<",
"x_len",
":",
"s",
"+=",
"\"%04x \"",
"%",
"i",... | Build a tcpdump like hexadecimal view
:param x: a Packet
:param dump: define if the result must be printed or returned in a variable
:returns: a String only when dump=True | [
"Build",
"a",
"tcpdump",
"like",
"hexadecimal",
"view"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L137-L162 | train |
secdev/scapy | scapy/utils.py | linehexdump | def linehexdump(x, onlyasc=0, onlyhex=0, dump=False):
"""Build an equivalent view of hexdump() on a single line
Note that setting both onlyasc and onlyhex to 1 results in a empty output
:param x: a Packet
:param onlyasc: 1 to display only the ascii view
:param onlyhex: 1 to display only the hexade... | python | def linehexdump(x, onlyasc=0, onlyhex=0, dump=False):
"""Build an equivalent view of hexdump() on a single line
Note that setting both onlyasc and onlyhex to 1 results in a empty output
:param x: a Packet
:param onlyasc: 1 to display only the ascii view
:param onlyhex: 1 to display only the hexade... | [
"def",
"linehexdump",
"(",
"x",
",",
"onlyasc",
"=",
"0",
",",
"onlyhex",
"=",
"0",
",",
"dump",
"=",
"False",
")",
":",
"s",
"=",
"\"\"",
"s",
"=",
"hexstr",
"(",
"x",
",",
"onlyasc",
"=",
"onlyasc",
",",
"onlyhex",
"=",
"onlyhex",
",",
"color",... | Build an equivalent view of hexdump() on a single line
Note that setting both onlyasc and onlyhex to 1 results in a empty output
:param x: a Packet
:param onlyasc: 1 to display only the ascii view
:param onlyhex: 1 to display only the hexadecimal view
:param dump: print the view if False
:retu... | [
"Build",
"an",
"equivalent",
"view",
"of",
"hexdump",
"()",
"on",
"a",
"single",
"line"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L166-L182 | train |
secdev/scapy | scapy/utils.py | chexdump | def chexdump(x, dump=False):
"""Build a per byte hexadecimal representation
Example:
>>> chexdump(IP())
0x45, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x7c, 0xe7, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01 # noqa: E501
:param x: a Packet
:param dump: print the view if... | python | def chexdump(x, dump=False):
"""Build a per byte hexadecimal representation
Example:
>>> chexdump(IP())
0x45, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x7c, 0xe7, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01 # noqa: E501
:param x: a Packet
:param dump: print the view if... | [
"def",
"chexdump",
"(",
"x",
",",
"dump",
"=",
"False",
")",
":",
"x",
"=",
"bytes_encode",
"(",
"x",
")",
"s",
"=",
"\", \"",
".",
"join",
"(",
"\"%#04x\"",
"%",
"orb",
"(",
"x",
")",
"for",
"x",
"in",
"x",
")",
"if",
"dump",
":",
"return",
... | Build a per byte hexadecimal representation
Example:
>>> chexdump(IP())
0x45, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x7c, 0xe7, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01 # noqa: E501
:param x: a Packet
:param dump: print the view if False
:returns: a String only i... | [
"Build",
"a",
"per",
"byte",
"hexadecimal",
"representation"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L186-L202 | train |
secdev/scapy | scapy/utils.py | hexstr | def hexstr(x, onlyasc=0, onlyhex=0, color=False):
"""Build a fancy tcpdump like hex from bytes."""
x = bytes_encode(x)
_sane_func = sane_color if color else sane
s = []
if not onlyasc:
s.append(" ".join("%02X" % orb(b) for b in x))
if not onlyhex:
s.append(_sane_func(x))
retu... | python | def hexstr(x, onlyasc=0, onlyhex=0, color=False):
"""Build a fancy tcpdump like hex from bytes."""
x = bytes_encode(x)
_sane_func = sane_color if color else sane
s = []
if not onlyasc:
s.append(" ".join("%02X" % orb(b) for b in x))
if not onlyhex:
s.append(_sane_func(x))
retu... | [
"def",
"hexstr",
"(",
"x",
",",
"onlyasc",
"=",
"0",
",",
"onlyhex",
"=",
"0",
",",
"color",
"=",
"False",
")",
":",
"x",
"=",
"bytes_encode",
"(",
"x",
")",
"_sane_func",
"=",
"sane_color",
"if",
"color",
"else",
"sane",
"s",
"=",
"[",
"]",
"if"... | Build a fancy tcpdump like hex from bytes. | [
"Build",
"a",
"fancy",
"tcpdump",
"like",
"hex",
"from",
"bytes",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L206-L215 | train |
secdev/scapy | scapy/utils.py | hexdiff | def hexdiff(x, y):
"""Show differences between 2 binary strings"""
x = bytes_encode(x)[::-1]
y = bytes_encode(y)[::-1]
SUBST = 1
INSERT = 1
d = {(-1, -1): (0, (-1, -1))}
for j in range(len(y)):
d[-1, j] = d[-1, j - 1][0] + INSERT, (-1, j - 1)
for i in range(len(x)):
d[i, ... | python | def hexdiff(x, y):
"""Show differences between 2 binary strings"""
x = bytes_encode(x)[::-1]
y = bytes_encode(y)[::-1]
SUBST = 1
INSERT = 1
d = {(-1, -1): (0, (-1, -1))}
for j in range(len(y)):
d[-1, j] = d[-1, j - 1][0] + INSERT, (-1, j - 1)
for i in range(len(x)):
d[i, ... | [
"def",
"hexdiff",
"(",
"x",
",",
"y",
")",
":",
"x",
"=",
"bytes_encode",
"(",
"x",
")",
"[",
":",
":",
"-",
"1",
"]",
"y",
"=",
"bytes_encode",
"(",
"y",
")",
"[",
":",
":",
"-",
"1",
"]",
"SUBST",
"=",
"1",
"INSERT",
"=",
"1",
"d",
"=",... | Show differences between 2 binary strings | [
"Show",
"differences",
"between",
"2",
"binary",
"strings"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L224-L325 | train |
secdev/scapy | scapy/utils.py | fletcher16_checkbytes | def fletcher16_checkbytes(binbuf, offset):
"""Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string.
Including the bytes into the buffer (at the position marked by offset) the # noqa: E501
global Fletcher-16 checksum of the buffer will be 0. Thus it is easy to verify # noqa: E501
... | python | def fletcher16_checkbytes(binbuf, offset):
"""Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string.
Including the bytes into the buffer (at the position marked by offset) the # noqa: E501
global Fletcher-16 checksum of the buffer will be 0. Thus it is easy to verify # noqa: E501
... | [
"def",
"fletcher16_checkbytes",
"(",
"binbuf",
",",
"offset",
")",
":",
"# This is based on the GPLed C implementation in Zebra <http://www.zebra.org/> # noqa: E501",
"if",
"len",
"(",
"binbuf",
")",
"<",
"offset",
":",
"raise",
"Exception",
"(",
"\"Packet too short for chec... | Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string.
Including the bytes into the buffer (at the position marked by offset) the # noqa: E501
global Fletcher-16 checksum of the buffer will be 0. Thus it is easy to verify # noqa: E501
the integrity of the buffer on the receiver ... | [
"Calculates",
"the",
"Fletcher",
"-",
"16",
"checkbytes",
"returned",
"as",
"2",
"byte",
"binary",
"-",
"string",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L373-L399 | train |
secdev/scapy | scapy/utils.py | randstring | def randstring(l):
"""
Returns a random string of length l (l >= 0)
"""
return b"".join(struct.pack('B', random.randint(0, 255)) for _ in range(l)) | python | def randstring(l):
"""
Returns a random string of length l (l >= 0)
"""
return b"".join(struct.pack('B', random.randint(0, 255)) for _ in range(l)) | [
"def",
"randstring",
"(",
"l",
")",
":",
"return",
"b\"\"",
".",
"join",
"(",
"struct",
".",
"pack",
"(",
"'B'",
",",
"random",
".",
"randint",
"(",
"0",
",",
"255",
")",
")",
"for",
"_",
"in",
"range",
"(",
"l",
")",
")"
] | Returns a random string of length l (l >= 0) | [
"Returns",
"a",
"random",
"string",
"of",
"length",
"l",
"(",
"l",
">",
"=",
"0",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L420-L424 | train |
secdev/scapy | scapy/utils.py | strxor | def strxor(s1, s2):
"""
Returns the binary XOR of the 2 provided strings s1 and s2. s1 and s2
must be of same length.
"""
return b"".join(map(lambda x, y: chb(orb(x) ^ orb(y)), s1, s2)) | python | def strxor(s1, s2):
"""
Returns the binary XOR of the 2 provided strings s1 and s2. s1 and s2
must be of same length.
"""
return b"".join(map(lambda x, y: chb(orb(x) ^ orb(y)), s1, s2)) | [
"def",
"strxor",
"(",
"s1",
",",
"s2",
")",
":",
"return",
"b\"\"",
".",
"join",
"(",
"map",
"(",
"lambda",
"x",
",",
"y",
":",
"chb",
"(",
"orb",
"(",
"x",
")",
"^",
"orb",
"(",
"y",
")",
")",
",",
"s1",
",",
"s2",
")",
")"
] | Returns the binary XOR of the 2 provided strings s1 and s2. s1 and s2
must be of same length. | [
"Returns",
"the",
"binary",
"XOR",
"of",
"the",
"2",
"provided",
"strings",
"s1",
"and",
"s2",
".",
"s1",
"and",
"s2",
"must",
"be",
"of",
"same",
"length",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L434-L439 | train |
secdev/scapy | scapy/utils.py | do_graph | def do_graph(graph, prog=None, format=None, target=None, type=None, string=None, options=None): # noqa: E501
"""do_graph(graph, prog=conf.prog.dot, format="svg",
target="| conf.prog.display", options=None, [string=1]):
string: if not None, simply return the graph string
graph: GraphViz graph descr... | python | def do_graph(graph, prog=None, format=None, target=None, type=None, string=None, options=None): # noqa: E501
"""do_graph(graph, prog=conf.prog.dot, format="svg",
target="| conf.prog.display", options=None, [string=1]):
string: if not None, simply return the graph string
graph: GraphViz graph descr... | [
"def",
"do_graph",
"(",
"graph",
",",
"prog",
"=",
"None",
",",
"format",
"=",
"None",
",",
"target",
"=",
"None",
",",
"type",
"=",
"None",
",",
"string",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"# noqa: E501",
"if",
"format",
"is",
"N... | do_graph(graph, prog=conf.prog.dot, format="svg",
target="| conf.prog.display", options=None, [string=1]):
string: if not None, simply return the graph string
graph: GraphViz graph description
format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" option
target: filename or redirec... | [
"do_graph",
"(",
"graph",
"prog",
"=",
"conf",
".",
"prog",
".",
"dot",
"format",
"=",
"svg",
"target",
"=",
"|",
"conf",
".",
"prog",
".",
"display",
"options",
"=",
"None",
"[",
"string",
"=",
"1",
"]",
")",
":",
"string",
":",
"if",
"not",
"No... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L600-L662 | train |
secdev/scapy | scapy/utils.py | save_object | def save_object(fname, obj):
"""Pickle a Python object"""
fd = gzip.open(fname, "wb")
six.moves.cPickle.dump(obj, fd)
fd.close() | python | def save_object(fname, obj):
"""Pickle a Python object"""
fd = gzip.open(fname, "wb")
six.moves.cPickle.dump(obj, fd)
fd.close() | [
"def",
"save_object",
"(",
"fname",
",",
"obj",
")",
":",
"fd",
"=",
"gzip",
".",
"open",
"(",
"fname",
",",
"\"wb\"",
")",
"six",
".",
"moves",
".",
"cPickle",
".",
"dump",
"(",
"obj",
",",
"fd",
")",
"fd",
".",
"close",
"(",
")"
] | Pickle a Python object | [
"Pickle",
"a",
"Python",
"object"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L794-L799 | train |
secdev/scapy | scapy/utils.py | corrupt_bytes | def corrupt_bytes(s, p=0.01, n=None):
"""Corrupt a given percentage or number of bytes from a string"""
s = array.array("B", bytes_encode(s))
s_len = len(s)
if n is None:
n = max(1, int(s_len * p))
for i in random.sample(range(s_len), n):
s[i] = (s[i] + random.randint(1, 255)) % 256
... | python | def corrupt_bytes(s, p=0.01, n=None):
"""Corrupt a given percentage or number of bytes from a string"""
s = array.array("B", bytes_encode(s))
s_len = len(s)
if n is None:
n = max(1, int(s_len * p))
for i in random.sample(range(s_len), n):
s[i] = (s[i] + random.randint(1, 255)) % 256
... | [
"def",
"corrupt_bytes",
"(",
"s",
",",
"p",
"=",
"0.01",
",",
"n",
"=",
"None",
")",
":",
"s",
"=",
"array",
".",
"array",
"(",
"\"B\"",
",",
"bytes_encode",
"(",
"s",
")",
")",
"s_len",
"=",
"len",
"(",
"s",
")",
"if",
"n",
"is",
"None",
":"... | Corrupt a given percentage or number of bytes from a string | [
"Corrupt",
"a",
"given",
"percentage",
"or",
"number",
"of",
"bytes",
"from",
"a",
"string"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L808-L816 | train |
secdev/scapy | scapy/utils.py | wrpcap | def wrpcap(filename, pkt, *args, **kargs):
"""Write a list of packets to a pcap file
filename: the name of the file to write packets to, or an open,
writable file-like object. The file descriptor will be
closed at the end of the call, so do not use an object you
do not want to close (... | python | def wrpcap(filename, pkt, *args, **kargs):
"""Write a list of packets to a pcap file
filename: the name of the file to write packets to, or an open,
writable file-like object. The file descriptor will be
closed at the end of the call, so do not use an object you
do not want to close (... | [
"def",
"wrpcap",
"(",
"filename",
",",
"pkt",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"with",
"PcapWriter",
"(",
"filename",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
"as",
"fdesc",
":",
"fdesc",
".",
"write",
"(",
"pkt",
")"
] | Write a list of packets to a pcap file
filename: the name of the file to write packets to, or an open,
writable file-like object. The file descriptor will be
closed at the end of the call, so do not use an object you
do not want to close (e.g., running wrpcap(sys.stdout, [])
in ... | [
"Write",
"a",
"list",
"of",
"packets",
"to",
"a",
"pcap",
"file"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L836-L851 | train |
secdev/scapy | scapy/utils.py | rdpcap | def rdpcap(filename, count=-1):
"""Read a pcap or pcapng file and return a packet list
count: read only <count> packets
"""
with PcapReader(filename) as fdesc:
return fdesc.read_all(count=count) | python | def rdpcap(filename, count=-1):
"""Read a pcap or pcapng file and return a packet list
count: read only <count> packets
"""
with PcapReader(filename) as fdesc:
return fdesc.read_all(count=count) | [
"def",
"rdpcap",
"(",
"filename",
",",
"count",
"=",
"-",
"1",
")",
":",
"with",
"PcapReader",
"(",
"filename",
")",
"as",
"fdesc",
":",
"return",
"fdesc",
".",
"read_all",
"(",
"count",
"=",
"count",
")"
] | Read a pcap or pcapng file and return a packet list
count: read only <count> packets | [
"Read",
"a",
"pcap",
"or",
"pcapng",
"file",
"and",
"return",
"a",
"packet",
"list"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L855-L862 | train |
secdev/scapy | scapy/utils.py | import_hexcap | def import_hexcap():
"""Imports a tcpdump like hexadecimal view
e.g: exported via hexdump() or tcpdump or wireshark's "export as hex"
"""
re_extract_hexcap = re.compile(r"^((0x)?[0-9a-fA-F]{2,}[ :\t]{,3}|) *(([0-9a-fA-F]{2} {,2}){,16})") # noqa: E501
p = ""
try:
while True:
... | python | def import_hexcap():
"""Imports a tcpdump like hexadecimal view
e.g: exported via hexdump() or tcpdump or wireshark's "export as hex"
"""
re_extract_hexcap = re.compile(r"^((0x)?[0-9a-fA-F]{2,}[ :\t]{,3}|) *(([0-9a-fA-F]{2} {,2}){,16})") # noqa: E501
p = ""
try:
while True:
... | [
"def",
"import_hexcap",
"(",
")",
":",
"re_extract_hexcap",
"=",
"re",
".",
"compile",
"(",
"r\"^((0x)?[0-9a-fA-F]{2,}[ :\\t]{,3}|) *(([0-9a-fA-F]{2} {,2}){,16})\"",
")",
"# noqa: E501",
"p",
"=",
"\"\"",
"try",
":",
"while",
"True",
":",
"line",
"=",
"input",
"(",
... | Imports a tcpdump like hexadecimal view
e.g: exported via hexdump() or tcpdump or wireshark's "export as hex" | [
"Imports",
"a",
"tcpdump",
"like",
"hexadecimal",
"view"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1421-L1442 | train |
secdev/scapy | scapy/utils.py | wireshark | def wireshark(pktlist, wait=False, **kwargs):
"""
Runs Wireshark on a list of packets.
See :func:`tcpdump` for more parameter description.
Note: this defaults to wait=False, to run Wireshark in the background.
"""
return tcpdump(pktlist, prog=conf.prog.wireshark, wait=wait, **kwargs) | python | def wireshark(pktlist, wait=False, **kwargs):
"""
Runs Wireshark on a list of packets.
See :func:`tcpdump` for more parameter description.
Note: this defaults to wait=False, to run Wireshark in the background.
"""
return tcpdump(pktlist, prog=conf.prog.wireshark, wait=wait, **kwargs) | [
"def",
"wireshark",
"(",
"pktlist",
",",
"wait",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"tcpdump",
"(",
"pktlist",
",",
"prog",
"=",
"conf",
".",
"prog",
".",
"wireshark",
",",
"wait",
"=",
"wait",
",",
"*",
"*",
"kwargs",
")"
] | Runs Wireshark on a list of packets.
See :func:`tcpdump` for more parameter description.
Note: this defaults to wait=False, to run Wireshark in the background. | [
"Runs",
"Wireshark",
"on",
"a",
"list",
"of",
"packets",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1446-L1454 | train |
secdev/scapy | scapy/utils.py | tdecode | def tdecode(pktlist, args=None, **kwargs):
"""
Run tshark on a list of packets.
:param args: If not specified, defaults to ``tshark -V``.
See :func:`tcpdump` for more parameters.
"""
if args is None:
args = ["-V"]
return tcpdump(pktlist, prog=conf.prog.tshark, args=args, **kwargs) | python | def tdecode(pktlist, args=None, **kwargs):
"""
Run tshark on a list of packets.
:param args: If not specified, defaults to ``tshark -V``.
See :func:`tcpdump` for more parameters.
"""
if args is None:
args = ["-V"]
return tcpdump(pktlist, prog=conf.prog.tshark, args=args, **kwargs) | [
"def",
"tdecode",
"(",
"pktlist",
",",
"args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"[",
"\"-V\"",
"]",
"return",
"tcpdump",
"(",
"pktlist",
",",
"prog",
"=",
"conf",
".",
"prog",
".",
"tsh... | Run tshark on a list of packets.
:param args: If not specified, defaults to ``tshark -V``.
See :func:`tcpdump` for more parameters. | [
"Run",
"tshark",
"on",
"a",
"list",
"of",
"packets",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1458-L1468 | train |
secdev/scapy | scapy/utils.py | tcpdump | def tcpdump(pktlist, dump=False, getfd=False, args=None,
prog=None, getproc=False, quiet=False, use_tempfile=None,
read_stdin_opts=None, linktype=None, wait=True):
"""Run tcpdump or tshark on a list of packets.
When using ``tcpdump`` on OSX (``prog == conf.prog.tcpdump``), this uses a
... | python | def tcpdump(pktlist, dump=False, getfd=False, args=None,
prog=None, getproc=False, quiet=False, use_tempfile=None,
read_stdin_opts=None, linktype=None, wait=True):
"""Run tcpdump or tshark on a list of packets.
When using ``tcpdump`` on OSX (``prog == conf.prog.tcpdump``), this uses a
... | [
"def",
"tcpdump",
"(",
"pktlist",
",",
"dump",
"=",
"False",
",",
"getfd",
"=",
"False",
",",
"args",
"=",
"None",
",",
"prog",
"=",
"None",
",",
"getproc",
"=",
"False",
",",
"quiet",
"=",
"False",
",",
"use_tempfile",
"=",
"None",
",",
"read_stdin_... | Run tcpdump or tshark on a list of packets.
When using ``tcpdump`` on OSX (``prog == conf.prog.tcpdump``), this uses a
temporary file to store the packets. This works around a bug in Apple's
version of ``tcpdump``: http://apple.stackexchange.com/questions/152682/
Otherwise, the packets are passed in s... | [
"Run",
"tcpdump",
"or",
"tshark",
"on",
"a",
"list",
"of",
"packets",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1472-L1644 | train |
secdev/scapy | scapy/utils.py | hexedit | def hexedit(pktlist):
"""Run hexedit on a list of packets, then return the edited packets."""
f = get_temp_file()
wrpcap(f, pktlist)
with ContextManagerSubprocess("hexedit()", conf.prog.hexedit):
subprocess.call([conf.prog.hexedit, f])
pktlist = rdpcap(f)
os.unlink(f)
return pktlist | python | def hexedit(pktlist):
"""Run hexedit on a list of packets, then return the edited packets."""
f = get_temp_file()
wrpcap(f, pktlist)
with ContextManagerSubprocess("hexedit()", conf.prog.hexedit):
subprocess.call([conf.prog.hexedit, f])
pktlist = rdpcap(f)
os.unlink(f)
return pktlist | [
"def",
"hexedit",
"(",
"pktlist",
")",
":",
"f",
"=",
"get_temp_file",
"(",
")",
"wrpcap",
"(",
"f",
",",
"pktlist",
")",
"with",
"ContextManagerSubprocess",
"(",
"\"hexedit()\"",
",",
"conf",
".",
"prog",
".",
"hexedit",
")",
":",
"subprocess",
".",
"ca... | Run hexedit on a list of packets, then return the edited packets. | [
"Run",
"hexedit",
"on",
"a",
"list",
"of",
"packets",
"then",
"return",
"the",
"edited",
"packets",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1648-L1656 | train |
secdev/scapy | scapy/utils.py | get_terminal_width | def get_terminal_width():
"""Get terminal width (number of characters) if in a window.
Notice: this will try several methods in order to
support as many terminals and OS as possible.
"""
# Let's first try using the official API
# (Python 3.3+)
if not six.PY2:
import shutil
s... | python | def get_terminal_width():
"""Get terminal width (number of characters) if in a window.
Notice: this will try several methods in order to
support as many terminals and OS as possible.
"""
# Let's first try using the official API
# (Python 3.3+)
if not six.PY2:
import shutil
s... | [
"def",
"get_terminal_width",
"(",
")",
":",
"# Let's first try using the official API",
"# (Python 3.3+)",
"if",
"not",
"six",
".",
"PY2",
":",
"import",
"shutil",
"sizex",
"=",
"shutil",
".",
"get_terminal_size",
"(",
"fallback",
"=",
"(",
"0",
",",
"0",
")",
... | Get terminal width (number of characters) if in a window.
Notice: this will try several methods in order to
support as many terminals and OS as possible. | [
"Get",
"terminal",
"width",
"(",
"number",
"of",
"characters",
")",
"if",
"in",
"a",
"window",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1659-L1705 | train |
secdev/scapy | scapy/utils.py | pretty_list | def pretty_list(rtlst, header, sortBy=0, borders=False):
"""Pretty list to fit the terminal, and add header"""
if borders:
_space = "|"
else:
_space = " "
# Windows has a fat terminal border
_spacelen = len(_space) * (len(header) - 1) + (10 if WINDOWS else 0)
_croped = False
... | python | def pretty_list(rtlst, header, sortBy=0, borders=False):
"""Pretty list to fit the terminal, and add header"""
if borders:
_space = "|"
else:
_space = " "
# Windows has a fat terminal border
_spacelen = len(_space) * (len(header) - 1) + (10 if WINDOWS else 0)
_croped = False
... | [
"def",
"pretty_list",
"(",
"rtlst",
",",
"header",
",",
"sortBy",
"=",
"0",
",",
"borders",
"=",
"False",
")",
":",
"if",
"borders",
":",
"_space",
"=",
"\"|\"",
"else",
":",
"_space",
"=",
"\" \"",
"# Windows has a fat terminal border",
"_spacelen",
"=",
... | Pretty list to fit the terminal, and add header | [
"Pretty",
"list",
"to",
"fit",
"the",
"terminal",
"and",
"add",
"header"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1708-L1752 | train |
secdev/scapy | scapy/utils.py | __make_table | def __make_table(yfmtfunc, fmtfunc, endline, data, fxyz, sortx=None, sorty=None, seplinefunc=None): # noqa: E501
"""Core function of the make_table suite, which generates the table"""
vx = {}
vy = {}
vz = {}
vxf = {}
# Python 2 backward compatibility
fxyz = lambda_tuple_converter(fxyz)
... | python | def __make_table(yfmtfunc, fmtfunc, endline, data, fxyz, sortx=None, sorty=None, seplinefunc=None): # noqa: E501
"""Core function of the make_table suite, which generates the table"""
vx = {}
vy = {}
vz = {}
vxf = {}
# Python 2 backward compatibility
fxyz = lambda_tuple_converter(fxyz)
... | [
"def",
"__make_table",
"(",
"yfmtfunc",
",",
"fmtfunc",
",",
"endline",
",",
"data",
",",
"fxyz",
",",
"sortx",
"=",
"None",
",",
"sorty",
"=",
"None",
",",
"seplinefunc",
"=",
"None",
")",
":",
"# noqa: E501",
"vx",
"=",
"{",
"}",
"vy",
"=",
"{",
... | Core function of the make_table suite, which generates the table | [
"Core",
"function",
"of",
"the",
"make_table",
"suite",
"which",
"generates",
"the",
"table"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1755-L1814 | train |
secdev/scapy | scapy/utils.py | whois | def whois(ip_address):
"""Whois client for Python"""
whois_ip = str(ip_address)
try:
query = socket.gethostbyname(whois_ip)
except Exception:
query = whois_ip
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("whois.ripe.net", 43))
s.send(query.encode("utf8") +... | python | def whois(ip_address):
"""Whois client for Python"""
whois_ip = str(ip_address)
try:
query = socket.gethostbyname(whois_ip)
except Exception:
query = whois_ip
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("whois.ripe.net", 43))
s.send(query.encode("utf8") +... | [
"def",
"whois",
"(",
"ip_address",
")",
":",
"whois_ip",
"=",
"str",
"(",
"ip_address",
")",
"try",
":",
"query",
"=",
"socket",
".",
"gethostbyname",
"(",
"whois_ip",
")",
"except",
"Exception",
":",
"query",
"=",
"whois_ip",
"s",
"=",
"socket",
".",
... | Whois client for Python | [
"Whois",
"client",
"for",
"Python"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1835-L1861 | train |
secdev/scapy | scapy/utils.py | PcapReader_metaclass.open | def open(filename):
"""Open (if necessary) filename, and read the magic."""
if isinstance(filename, six.string_types):
try:
fdesc = gzip.open(filename, "rb")
magic = fdesc.read(4)
except IOError:
fdesc = open(filename, "rb")
... | python | def open(filename):
"""Open (if necessary) filename, and read the magic."""
if isinstance(filename, six.string_types):
try:
fdesc = gzip.open(filename, "rb")
magic = fdesc.read(4)
except IOError:
fdesc = open(filename, "rb")
... | [
"def",
"open",
"(",
"filename",
")",
":",
"if",
"isinstance",
"(",
"filename",
",",
"six",
".",
"string_types",
")",
":",
"try",
":",
"fdesc",
"=",
"gzip",
".",
"open",
"(",
"filename",
",",
"\"rb\"",
")",
"magic",
"=",
"fdesc",
".",
"read",
"(",
"... | Open (if necessary) filename, and read the magic. | [
"Open",
"(",
"if",
"necessary",
")",
"filename",
"and",
"read",
"the",
"magic",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L904-L917 | train |
secdev/scapy | scapy/utils.py | RawPcapReader.read_all | def read_all(self, count=-1):
"""return a list of all packets in the pcap file
"""
res = []
while count != 0:
count -= 1
p = self.read_packet()
if p is None:
break
res.append(p)
return res | python | def read_all(self, count=-1):
"""return a list of all packets in the pcap file
"""
res = []
while count != 0:
count -= 1
p = self.read_packet()
if p is None:
break
res.append(p)
return res | [
"def",
"read_all",
"(",
"self",
",",
"count",
"=",
"-",
"1",
")",
":",
"res",
"=",
"[",
"]",
"while",
"count",
"!=",
"0",
":",
"count",
"-=",
"1",
"p",
"=",
"self",
".",
"read_packet",
"(",
")",
"if",
"p",
"is",
"None",
":",
"break",
"res",
"... | return a list of all packets in the pcap file | [
"return",
"a",
"list",
"of",
"all",
"packets",
"in",
"the",
"pcap",
"file"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L988-L998 | train |
secdev/scapy | scapy/utils.py | RawPcapNgReader.read_packet | def read_packet(self, size=MTU):
"""Read blocks until it reaches either EOF or a packet, and
returns None or (packet, (linktype, sec, usec, wirelen)),
where packet is a string.
"""
while True:
try:
blocktype, blocklen = struct.unpack(self.endian + "2I... | python | def read_packet(self, size=MTU):
"""Read blocks until it reaches either EOF or a packet, and
returns None or (packet, (linktype, sec, usec, wirelen)),
where packet is a string.
"""
while True:
try:
blocktype, blocklen = struct.unpack(self.endian + "2I... | [
"def",
"read_packet",
"(",
"self",
",",
"size",
"=",
"MTU",
")",
":",
"while",
"True",
":",
"try",
":",
"blocktype",
",",
"blocklen",
"=",
"struct",
".",
"unpack",
"(",
"self",
".",
"endian",
"+",
"\"2I\"",
",",
"self",
".",
"f",
".",
"read",
"(",
... | Read blocks until it reaches either EOF or a packet, and
returns None or (packet, (linktype, sec, usec, wirelen)),
where packet is a string. | [
"Read",
"blocks",
"until",
"it",
"reaches",
"either",
"EOF",
"or",
"a",
"packet",
"and",
"returns",
"None",
"or",
"(",
"packet",
"(",
"linktype",
"sec",
"usec",
"wirelen",
"))",
"where",
"packet",
"is",
"a",
"string",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1101-L1127 | train |
secdev/scapy | scapy/utils.py | RawPcapNgReader.read_block_idb | def read_block_idb(self, block, _):
"""Interface Description Block"""
options = block[16:]
tsresol = 1000000
while len(options) >= 4:
code, length = struct.unpack(self.endian + "HH", options[:4])
# PCAP Next Generation (pcapng) Capture File Format
# 4.... | python | def read_block_idb(self, block, _):
"""Interface Description Block"""
options = block[16:]
tsresol = 1000000
while len(options) >= 4:
code, length = struct.unpack(self.endian + "HH", options[:4])
# PCAP Next Generation (pcapng) Capture File Format
# 4.... | [
"def",
"read_block_idb",
"(",
"self",
",",
"block",
",",
"_",
")",
":",
"options",
"=",
"block",
"[",
"16",
":",
"]",
"tsresol",
"=",
"1000000",
"while",
"len",
"(",
"options",
")",
">=",
"4",
":",
"code",
",",
"length",
"=",
"struct",
".",
"unpack... | Interface Description Block | [
"Interface",
"Description",
"Block"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1129-L1149 | train |
secdev/scapy | scapy/utils.py | RawPcapNgReader.read_block_epb | def read_block_epb(self, block, size):
"""Enhanced Packet Block"""
intid, tshigh, tslow, caplen, wirelen = struct.unpack(
self.endian + "5I",
block[:20],
)
return (block[20:20 + caplen][:size],
RawPcapNgReader.PacketMetadata(linktype=self.interface... | python | def read_block_epb(self, block, size):
"""Enhanced Packet Block"""
intid, tshigh, tslow, caplen, wirelen = struct.unpack(
self.endian + "5I",
block[:20],
)
return (block[20:20 + caplen][:size],
RawPcapNgReader.PacketMetadata(linktype=self.interface... | [
"def",
"read_block_epb",
"(",
"self",
",",
"block",
",",
"size",
")",
":",
"intid",
",",
"tshigh",
",",
"tslow",
",",
"caplen",
",",
"wirelen",
"=",
"struct",
".",
"unpack",
"(",
"self",
".",
"endian",
"+",
"\"5I\"",
",",
"block",
"[",
":",
"20",
"... | Enhanced Packet Block | [
"Enhanced",
"Packet",
"Block"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1151-L1162 | train |
secdev/scapy | scapy/utils.py | RawPcapWriter.write | def write(self, pkt):
"""
Writes a Packet or bytes to a pcap file.
:param pkt: Packet(s) to write (one record for each Packet), or raw
bytes to write (as one record).
:type pkt: iterable[Packet], Packet or bytes
"""
if isinstance(pkt, bytes):
... | python | def write(self, pkt):
"""
Writes a Packet or bytes to a pcap file.
:param pkt: Packet(s) to write (one record for each Packet), or raw
bytes to write (as one record).
:type pkt: iterable[Packet], Packet or bytes
"""
if isinstance(pkt, bytes):
... | [
"def",
"write",
"(",
"self",
",",
"pkt",
")",
":",
"if",
"isinstance",
"(",
"pkt",
",",
"bytes",
")",
":",
"if",
"not",
"self",
".",
"header_present",
":",
"self",
".",
"_write_header",
"(",
"pkt",
")",
"self",
".",
"_write_packet",
"(",
"pkt",
")",
... | Writes a Packet or bytes to a pcap file.
:param pkt: Packet(s) to write (one record for each Packet), or raw
bytes to write (as one record).
:type pkt: iterable[Packet], Packet or bytes | [
"Writes",
"a",
"Packet",
"or",
"bytes",
"to",
"a",
"pcap",
"file",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1282-L1299 | train |
secdev/scapy | scapy/utils.py | PcapWriter._write_packet | def _write_packet(self, packet, sec=None, usec=None, caplen=None,
wirelen=None):
"""
Writes a single packet to the pcap file.
:param packet: Packet, or bytes for a single packet
:type packet: Packet or bytes
:param sec: time the packet was captured, in seco... | python | def _write_packet(self, packet, sec=None, usec=None, caplen=None,
wirelen=None):
"""
Writes a single packet to the pcap file.
:param packet: Packet, or bytes for a single packet
:type packet: Packet or bytes
:param sec: time the packet was captured, in seco... | [
"def",
"_write_packet",
"(",
"self",
",",
"packet",
",",
"sec",
"=",
"None",
",",
"usec",
"=",
"None",
",",
"caplen",
"=",
"None",
",",
"wirelen",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"packet",
",",
"\"time\"",
")",
":",
"if",
"sec",
"is",
... | Writes a single packet to the pcap file.
:param packet: Packet, or bytes for a single packet
:type packet: Packet or bytes
:param sec: time the packet was captured, in seconds since epoch. If
not supplied, defaults to now.
:type sec: int or long
:param usec: ... | [
"Writes",
"a",
"single",
"packet",
"to",
"the",
"pcap",
"file",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/utils.py#L1373-L1417 | train |
secdev/scapy | scapy/modules/voip.py | voip_play | def voip_play(s1, lst=None, **kargs):
"""Play VoIP packets with RAW data that
are either sniffed either from an IP, or
specified as a list.
It will play only the incoming packets !
:param s1: The IP of the src of all VoIP packets.
:param lst: (optional) A list of packets to load
:type s1: ... | python | def voip_play(s1, lst=None, **kargs):
"""Play VoIP packets with RAW data that
are either sniffed either from an IP, or
specified as a list.
It will play only the incoming packets !
:param s1: The IP of the src of all VoIP packets.
:param lst: (optional) A list of packets to load
:type s1: ... | [
"def",
"voip_play",
"(",
"s1",
",",
"lst",
"=",
"None",
",",
"*",
"*",
"kargs",
")",
":",
"dsp",
",",
"rd",
"=",
"os",
".",
"popen2",
"(",
"sox_base",
"%",
"\"\"",
")",
"def",
"play",
"(",
"pkt",
")",
":",
"if",
"not",
"pkt",
":",
"return",
"... | Play VoIP packets with RAW data that
are either sniffed either from an IP, or
specified as a list.
It will play only the incoming packets !
:param s1: The IP of the src of all VoIP packets.
:param lst: (optional) A list of packets to load
:type s1: string
:type lst: list
:Example:
... | [
"Play",
"VoIP",
"packets",
"with",
"RAW",
"data",
"that",
"are",
"either",
"sniffed",
"either",
"from",
"an",
"IP",
"or",
"specified",
"as",
"a",
"list",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/voip.py#L49-L96 | train |
secdev/scapy | scapy/modules/voip.py | voip_play2 | def voip_play2(s1, **kargs):
"""
Same than voip_play, but will play
both incoming and outcoming packets.
The sound will surely suffer distortion.
Only supports sniffing.
.. seealso:: voip_play
to play only incoming packets.
"""
dsp, rd = os.popen2(sox_base % "-c 2")
global x1, ... | python | def voip_play2(s1, **kargs):
"""
Same than voip_play, but will play
both incoming and outcoming packets.
The sound will surely suffer distortion.
Only supports sniffing.
.. seealso:: voip_play
to play only incoming packets.
"""
dsp, rd = os.popen2(sox_base % "-c 2")
global x1, ... | [
"def",
"voip_play2",
"(",
"s1",
",",
"*",
"*",
"kargs",
")",
":",
"dsp",
",",
"rd",
"=",
"os",
".",
"popen2",
"(",
"sox_base",
"%",
"\"-c 2\"",
")",
"global",
"x1",
",",
"x2",
"x1",
"=",
"\"\"",
"x2",
"=",
"\"\"",
"def",
"play",
"(",
"pkt",
")"... | Same than voip_play, but will play
both incoming and outcoming packets.
The sound will surely suffer distortion.
Only supports sniffing.
.. seealso:: voip_play
to play only incoming packets. | [
"Same",
"than",
"voip_play",
"but",
"will",
"play",
"both",
"incoming",
"and",
"outcoming",
"packets",
".",
"The",
"sound",
"will",
"surely",
"suffer",
"distortion",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/voip.py#L105-L136 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | phantom_mode | def phantom_mode(pkt):
"""
We expect this. If tls_version is not set, this means we did not process
any complete ClientHello, so we're most probably reading/building a
signature_algorithms extension, hence we cannot be in phantom_mode.
However, if the tls_version has been set, we test for TLS 1.2.
... | python | def phantom_mode(pkt):
"""
We expect this. If tls_version is not set, this means we did not process
any complete ClientHello, so we're most probably reading/building a
signature_algorithms extension, hence we cannot be in phantom_mode.
However, if the tls_version has been set, we test for TLS 1.2.
... | [
"def",
"phantom_mode",
"(",
"pkt",
")",
":",
"if",
"not",
"pkt",
".",
"tls_session",
":",
"return",
"False",
"if",
"not",
"pkt",
".",
"tls_session",
".",
"tls_version",
":",
"return",
"False",
"return",
"pkt",
".",
"tls_session",
".",
"tls_version",
"<",
... | We expect this. If tls_version is not set, this means we did not process
any complete ClientHello, so we're most probably reading/building a
signature_algorithms extension, hence we cannot be in phantom_mode.
However, if the tls_version has been set, we test for TLS 1.2. | [
"We",
"expect",
"this",
".",
"If",
"tls_version",
"is",
"not",
"set",
"this",
"means",
"we",
"did",
"not",
"process",
"any",
"complete",
"ClientHello",
"so",
"we",
"re",
"most",
"probably",
"reading",
"/",
"building",
"a",
"signature_algorithms",
"extension",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L59-L70 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | phantom_decorate | def phantom_decorate(f, get_or_add):
"""
Decorator for version-dependent fields.
If get_or_add is True (means get), we return s, self.phantom_value.
If it is False (means add), we return s.
"""
def wrapper(*args):
self, pkt, s = args[:3]
if phantom_mode(pkt):
if get_o... | python | def phantom_decorate(f, get_or_add):
"""
Decorator for version-dependent fields.
If get_or_add is True (means get), we return s, self.phantom_value.
If it is False (means add), we return s.
"""
def wrapper(*args):
self, pkt, s = args[:3]
if phantom_mode(pkt):
if get_o... | [
"def",
"phantom_decorate",
"(",
"f",
",",
"get_or_add",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
")",
":",
"self",
",",
"pkt",
",",
"s",
"=",
"args",
"[",
":",
"3",
"]",
"if",
"phantom_mode",
"(",
"pkt",
")",
":",
"if",
"get_or_add",
":",
"r... | Decorator for version-dependent fields.
If get_or_add is True (means get), we return s, self.phantom_value.
If it is False (means add), we return s. | [
"Decorator",
"for",
"version",
"-",
"dependent",
"fields",
".",
"If",
"get_or_add",
"is",
"True",
"(",
"means",
"get",
")",
"we",
"return",
"s",
"self",
".",
"phantom_value",
".",
"If",
"it",
"is",
"False",
"(",
"means",
"add",
")",
"we",
"return",
"s"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L73-L86 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | SigLenField.addfield | def addfield(self, pkt, s, val):
"""With SSLv2 you will never be able to add a sig_len."""
v = pkt.tls_session.tls_version
if v and v < 0x0300:
return s
return super(SigLenField, self).addfield(pkt, s, val) | python | def addfield(self, pkt, s, val):
"""With SSLv2 you will never be able to add a sig_len."""
v = pkt.tls_session.tls_version
if v and v < 0x0300:
return s
return super(SigLenField, self).addfield(pkt, s, val) | [
"def",
"addfield",
"(",
"self",
",",
"pkt",
",",
"s",
",",
"val",
")",
":",
"v",
"=",
"pkt",
".",
"tls_session",
".",
"tls_version",
"if",
"v",
"and",
"v",
"<",
"0x0300",
":",
"return",
"s",
"return",
"super",
"(",
"SigLenField",
",",
"self",
")",
... | With SSLv2 you will never be able to add a sig_len. | [
"With",
"SSLv2",
"you",
"will",
"never",
"be",
"able",
"to",
"add",
"a",
"sig_len",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L119-L124 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | _TLSSignature._update_sig | def _update_sig(self, m, key):
"""
Sign 'm' with the PrivKey 'key' and update our own 'sig_val'.
Note that, even when 'sig_alg' is not None, we use the signature scheme
of the PrivKey (neither do we care to compare the both of them).
"""
if self.sig_alg is None:
... | python | def _update_sig(self, m, key):
"""
Sign 'm' with the PrivKey 'key' and update our own 'sig_val'.
Note that, even when 'sig_alg' is not None, we use the signature scheme
of the PrivKey (neither do we care to compare the both of them).
"""
if self.sig_alg is None:
... | [
"def",
"_update_sig",
"(",
"self",
",",
"m",
",",
"key",
")",
":",
"if",
"self",
".",
"sig_alg",
"is",
"None",
":",
"if",
"self",
".",
"tls_session",
".",
"tls_version",
">=",
"0x0300",
":",
"self",
".",
"sig_val",
"=",
"key",
".",
"sign",
"(",
"m"... | Sign 'm' with the PrivKey 'key' and update our own 'sig_val'.
Note that, even when 'sig_alg' is not None, we use the signature scheme
of the PrivKey (neither do we care to compare the both of them). | [
"Sign",
"m",
"with",
"the",
"PrivKey",
"key",
"and",
"update",
"our",
"own",
"sig_val",
".",
"Note",
"that",
"even",
"when",
"sig_alg",
"is",
"not",
"None",
"we",
"use",
"the",
"signature",
"scheme",
"of",
"the",
"PrivKey",
"(",
"neither",
"do",
"we",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L171-L188 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | _TLSSignature._verify_sig | def _verify_sig(self, m, cert):
"""
Verify that our own 'sig_val' carries the signature of 'm' by the
key associated to the Cert 'cert'.
"""
if self.sig_val:
if self.sig_alg:
h, sig = _tls_hash_sig[self.sig_alg].split('+')
if sig.endswi... | python | def _verify_sig(self, m, cert):
"""
Verify that our own 'sig_val' carries the signature of 'm' by the
key associated to the Cert 'cert'.
"""
if self.sig_val:
if self.sig_alg:
h, sig = _tls_hash_sig[self.sig_alg].split('+')
if sig.endswi... | [
"def",
"_verify_sig",
"(",
"self",
",",
"m",
",",
"cert",
")",
":",
"if",
"self",
".",
"sig_val",
":",
"if",
"self",
".",
"sig_alg",
":",
"h",
",",
"sig",
"=",
"_tls_hash_sig",
"[",
"self",
".",
"sig_alg",
"]",
".",
"split",
"(",
"'+'",
")",
"if"... | Verify that our own 'sig_val' carries the signature of 'm' by the
key associated to the Cert 'cert'. | [
"Verify",
"that",
"our",
"own",
"sig_val",
"carries",
"the",
"signature",
"of",
"m",
"by",
"the",
"key",
"associated",
"to",
"the",
"Cert",
"cert",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L190-L208 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | ServerDHParams.fill_missing | def fill_missing(self):
"""
We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
Note that we do not expect default_params.g to be more than 0xff.
... | python | def fill_missing(self):
"""
We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
Note that we do not expect default_params.g to be more than 0xff.
... | [
"def",
"fill_missing",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"tls_session",
"default_params",
"=",
"_ffdh_groups",
"[",
"'modp2048'",
"]",
"[",
"0",
"]",
".",
"parameter_numbers",
"(",
")",
"default_mLen",
"=",
"_ffdh_groups",
"[",
"'modp2048'",
"]",... | We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
Note that we do not expect default_params.g to be more than 0xff. | [
"We",
"do",
"not",
"want",
"TLSServerKeyExchange",
".",
"build",
"()",
"to",
"overload",
"and",
"recompute",
"things",
"every",
"time",
"it",
"is",
"called",
".",
"This",
"method",
"can",
"be",
"called",
"specifically",
"to",
"have",
"things",
"filled",
"in"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L311-L348 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | ServerDHParams.register_pubkey | def register_pubkey(self):
"""
XXX Check that the pubkey received is in the group.
"""
p = pkcs_os2ip(self.dh_p)
g = pkcs_os2ip(self.dh_g)
pn = dh.DHParameterNumbers(p, g)
y = pkcs_os2ip(self.dh_Ys)
public_numbers = dh.DHPublicNumbers(y, pn)
s = ... | python | def register_pubkey(self):
"""
XXX Check that the pubkey received is in the group.
"""
p = pkcs_os2ip(self.dh_p)
g = pkcs_os2ip(self.dh_g)
pn = dh.DHParameterNumbers(p, g)
y = pkcs_os2ip(self.dh_Ys)
public_numbers = dh.DHPublicNumbers(y, pn)
s = ... | [
"def",
"register_pubkey",
"(",
"self",
")",
":",
"p",
"=",
"pkcs_os2ip",
"(",
"self",
".",
"dh_p",
")",
"g",
"=",
"pkcs_os2ip",
"(",
"self",
".",
"dh_g",
")",
"pn",
"=",
"dh",
".",
"DHParameterNumbers",
"(",
"p",
",",
"g",
")",
"y",
"=",
"pkcs_os2i... | XXX Check that the pubkey received is in the group. | [
"XXX",
"Check",
"that",
"the",
"pubkey",
"received",
"is",
"in",
"the",
"group",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L351-L366 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | ServerECDHNamedCurveParams.fill_missing | def fill_missing(self):
"""
We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
XXX We should account for the point_format (before 'point' filling).... | python | def fill_missing(self):
"""
We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
XXX We should account for the point_format (before 'point' filling).... | [
"def",
"fill_missing",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"tls_session",
"if",
"self",
".",
"curve_type",
"is",
"None",
":",
"self",
".",
"curve_type",
"=",
"_tls_ec_curve_types",
"[",
"\"named_curve\"",
"]",
"if",
"self",
".",
"named_curve",
"i... | We do not want TLSServerKeyExchange.build() to overload and recompute
things every time it is called. This method can be called specifically
to have things filled in a smart fashion.
XXX We should account for the point_format (before 'point' filling). | [
"We",
"do",
"not",
"want",
"TLSServerKeyExchange",
".",
"build",
"()",
"to",
"overload",
"and",
"recompute",
"things",
"every",
"time",
"it",
"is",
"called",
".",
"This",
"method",
"can",
"be",
"called",
"specifically",
"to",
"have",
"things",
"filled",
"in"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L553-L603 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | ServerECDHNamedCurveParams.register_pubkey | def register_pubkey(self):
"""
XXX Support compressed point format.
XXX Check that the pubkey received is on the curve.
"""
# point_format = 0
# if self.point[0] in [b'\x02', b'\x03']:
# point_format = 1
curve_name = _tls_named_curves[self.named_curve]... | python | def register_pubkey(self):
"""
XXX Support compressed point format.
XXX Check that the pubkey received is on the curve.
"""
# point_format = 0
# if self.point[0] in [b'\x02', b'\x03']:
# point_format = 1
curve_name = _tls_named_curves[self.named_curve]... | [
"def",
"register_pubkey",
"(",
"self",
")",
":",
"# point_format = 0",
"# if self.point[0] in [b'\\x02', b'\\x03']:",
"# point_format = 1",
"curve_name",
"=",
"_tls_named_curves",
"[",
"self",
".",
"named_curve",
"]",
"curve",
"=",
"ec",
".",
"_CURVE_TYPES",
"[",
"cu... | XXX Support compressed point format.
XXX Check that the pubkey received is on the curve. | [
"XXX",
"Support",
"compressed",
"point",
"format",
".",
"XXX",
"Check",
"that",
"the",
"pubkey",
"received",
"is",
"on",
"the",
"curve",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L606-L623 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | ClientDiffieHellmanPublic.post_dissection | def post_dissection(self, m):
"""
First we update the client DHParams. Then, we try to update the server
DHParams generated during Server*DHParams building, with the shared
secret. Finally, we derive the session keys and update the context.
"""
s = self.tls_session
... | python | def post_dissection(self, m):
"""
First we update the client DHParams. Then, we try to update the server
DHParams generated during Server*DHParams building, with the shared
secret. Finally, we derive the session keys and update the context.
"""
s = self.tls_session
... | [
"def",
"post_dissection",
"(",
"self",
",",
"m",
")",
":",
"s",
"=",
"self",
".",
"tls_session",
"# if there are kx params and keys, we assume the crypto library is ok",
"if",
"s",
".",
"client_kx_ffdh_params",
":",
"y",
"=",
"pkcs_os2ip",
"(",
"self",
".",
"dh_Yc",... | First we update the client DHParams. Then, we try to update the server
DHParams generated during Server*DHParams building, with the shared
secret. Finally, we derive the session keys and update the context. | [
"First",
"we",
"update",
"the",
"client",
"DHParams",
".",
"Then",
"we",
"try",
"to",
"update",
"the",
"server",
"DHParams",
"generated",
"during",
"Server",
"*",
"DHParams",
"building",
"with",
"the",
"shared",
"secret",
".",
"Finally",
"we",
"derive",
"the... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L769-L787 | train |
secdev/scapy | scapy/layers/tls/keyexchange.py | EncryptedPreMasterSecret.post_build | def post_build(self, pkt, pay):
"""
We encrypt the premaster secret (the 48 bytes) with either the server
certificate or the temporary RSA key provided in a server key exchange
message. After that step, we add the 2 bytes to provide the length, as
described in implementation note... | python | def post_build(self, pkt, pay):
"""
We encrypt the premaster secret (the 48 bytes) with either the server
certificate or the temporary RSA key provided in a server key exchange
message. After that step, we add the 2 bytes to provide the length, as
described in implementation note... | [
"def",
"post_build",
"(",
"self",
",",
"pkt",
",",
"pay",
")",
":",
"enc",
"=",
"pkt",
"s",
"=",
"self",
".",
"tls_session",
"s",
".",
"pre_master_secret",
"=",
"enc",
"s",
".",
"compute_ms_and_derive_keys",
"(",
")",
"if",
"s",
".",
"server_tmp_rsa_key"... | We encrypt the premaster secret (the 48 bytes) with either the server
certificate or the temporary RSA key provided in a server key exchange
message. After that step, we add the 2 bytes to provide the length, as
described in implementation notes at the end of section 7.4.7.1. | [
"We",
"encrypt",
"the",
"premaster",
"secret",
"(",
"the",
"48",
"bytes",
")",
"with",
"either",
"the",
"server",
"certificate",
"or",
"the",
"temporary",
"RSA",
"key",
"provided",
"in",
"a",
"server",
"key",
"exchange",
"message",
".",
"After",
"that",
"s... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/keyexchange.py#L907-L930 | train |
secdev/scapy | scapy/compat.py | lambda_tuple_converter | def lambda_tuple_converter(func):
"""
Converts a Python 2 function as
lambda (x,y): x + y
In the Python 3 format:
lambda x,y : x + y
"""
if func is not None and func.__code__.co_argcount == 1:
return lambda *args: func(args[0] if len(args) == 1 else args)
else:
return... | python | def lambda_tuple_converter(func):
"""
Converts a Python 2 function as
lambda (x,y): x + y
In the Python 3 format:
lambda x,y : x + y
"""
if func is not None and func.__code__.co_argcount == 1:
return lambda *args: func(args[0] if len(args) == 1 else args)
else:
return... | [
"def",
"lambda_tuple_converter",
"(",
"func",
")",
":",
"if",
"func",
"is",
"not",
"None",
"and",
"func",
".",
"__code__",
".",
"co_argcount",
"==",
"1",
":",
"return",
"lambda",
"*",
"args",
":",
"func",
"(",
"args",
"[",
"0",
"]",
"if",
"len",
"(",... | Converts a Python 2 function as
lambda (x,y): x + y
In the Python 3 format:
lambda x,y : x + y | [
"Converts",
"a",
"Python",
"2",
"function",
"as",
"lambda",
"(",
"x",
"y",
")",
":",
"x",
"+",
"y",
"In",
"the",
"Python",
"3",
"format",
":",
"lambda",
"x",
"y",
":",
"x",
"+",
"y"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/compat.py#L23-L33 | train |
secdev/scapy | scapy/compat.py | base64_bytes | def base64_bytes(x):
"""Turn base64 into bytes"""
if six.PY2:
return base64.decodestring(x)
return base64.decodebytes(bytes_encode(x)) | python | def base64_bytes(x):
"""Turn base64 into bytes"""
if six.PY2:
return base64.decodestring(x)
return base64.decodebytes(bytes_encode(x)) | [
"def",
"base64_bytes",
"(",
"x",
")",
":",
"if",
"six",
".",
"PY2",
":",
"return",
"base64",
".",
"decodestring",
"(",
"x",
")",
"return",
"base64",
".",
"decodebytes",
"(",
"bytes_encode",
"(",
"x",
")",
")"
] | Turn base64 into bytes | [
"Turn",
"base64",
"into",
"bytes"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/compat.py#L88-L92 | train |
secdev/scapy | scapy/compat.py | bytes_base64 | def bytes_base64(x):
"""Turn bytes into base64"""
if six.PY2:
return base64.encodestring(x).replace('\n', '')
return base64.encodebytes(bytes_encode(x)).replace(b'\n', b'') | python | def bytes_base64(x):
"""Turn bytes into base64"""
if six.PY2:
return base64.encodestring(x).replace('\n', '')
return base64.encodebytes(bytes_encode(x)).replace(b'\n', b'') | [
"def",
"bytes_base64",
"(",
"x",
")",
":",
"if",
"six",
".",
"PY2",
":",
"return",
"base64",
".",
"encodestring",
"(",
"x",
")",
".",
"replace",
"(",
"'\\n'",
",",
"''",
")",
"return",
"base64",
".",
"encodebytes",
"(",
"bytes_encode",
"(",
"x",
")",... | Turn bytes into base64 | [
"Turn",
"bytes",
"into",
"base64"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/compat.py#L95-L99 | train |
secdev/scapy | scapy/layers/tls/record.py | _TLSMsgListField.m2i | def m2i(self, pkt, m):
"""
Try to parse one of the TLS subprotocols (ccs, alert, handshake or
application_data). This is used inside a loop managed by .getfield().
"""
cls = Raw
if pkt.type == 22:
if len(m) >= 1:
msgtype = orb(m[0])
... | python | def m2i(self, pkt, m):
"""
Try to parse one of the TLS subprotocols (ccs, alert, handshake or
application_data). This is used inside a loop managed by .getfield().
"""
cls = Raw
if pkt.type == 22:
if len(m) >= 1:
msgtype = orb(m[0])
... | [
"def",
"m2i",
"(",
"self",
",",
"pkt",
",",
"m",
")",
":",
"cls",
"=",
"Raw",
"if",
"pkt",
".",
"type",
"==",
"22",
":",
"if",
"len",
"(",
"m",
")",
">=",
"1",
":",
"msgtype",
"=",
"orb",
"(",
"m",
"[",
"0",
"]",
")",
"cls",
"=",
"_tls_ha... | Try to parse one of the TLS subprotocols (ccs, alert, handshake or
application_data). This is used inside a loop managed by .getfield(). | [
"Try",
"to",
"parse",
"one",
"of",
"the",
"TLS",
"subprotocols",
"(",
"ccs",
"alert",
"handshake",
"or",
"application_data",
")",
".",
"This",
"is",
"used",
"inside",
"a",
"loop",
"managed",
"by",
".",
"getfield",
"()",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L83-L108 | train |
secdev/scapy | scapy/layers/tls/record.py | _TLSMsgListField.getfield | def getfield(self, pkt, s):
"""
If the decryption of the content did not fail with a CipherError,
we begin a loop on the clear content in order to get as much messages
as possible, of the type advertised in the record header. This is
notably important for several TLS handshake im... | python | def getfield(self, pkt, s):
"""
If the decryption of the content did not fail with a CipherError,
we begin a loop on the clear content in order to get as much messages
as possible, of the type advertised in the record header. This is
notably important for several TLS handshake im... | [
"def",
"getfield",
"(",
"self",
",",
"pkt",
",",
"s",
")",
":",
"tmp_len",
"=",
"self",
".",
"length_from",
"(",
"pkt",
")",
"lst",
"=",
"[",
"]",
"ret",
"=",
"b\"\"",
"remain",
"=",
"s",
"if",
"tmp_len",
"is",
"not",
"None",
":",
"remain",
",",
... | If the decryption of the content did not fail with a CipherError,
we begin a loop on the clear content in order to get as much messages
as possible, of the type advertised in the record header. This is
notably important for several TLS handshake implementations, which
may for instance pa... | [
"If",
"the",
"decryption",
"of",
"the",
"content",
"did",
"not",
"fail",
"with",
"a",
"CipherError",
"we",
"begin",
"a",
"loop",
"on",
"the",
"clear",
"content",
"in",
"order",
"to",
"get",
"as",
"much",
"messages",
"as",
"possible",
"of",
"the",
"type",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L110-L159 | train |
secdev/scapy | scapy/layers/tls/record.py | _TLSMsgListField.i2m | def i2m(self, pkt, p):
"""
Update the context with information from the built packet.
If no type was given at the record layer, we try to infer it.
"""
cur = b""
if isinstance(p, _GenericTLSSessionInheritance):
if pkt.type is None:
if isinstanc... | python | def i2m(self, pkt, p):
"""
Update the context with information from the built packet.
If no type was given at the record layer, we try to infer it.
"""
cur = b""
if isinstance(p, _GenericTLSSessionInheritance):
if pkt.type is None:
if isinstanc... | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"p",
")",
":",
"cur",
"=",
"b\"\"",
"if",
"isinstance",
"(",
"p",
",",
"_GenericTLSSessionInheritance",
")",
":",
"if",
"pkt",
".",
"type",
"is",
"None",
":",
"if",
"isinstance",
"(",
"p",
",",
"TLSChangeCi... | Update the context with information from the built packet.
If no type was given at the record layer, we try to infer it. | [
"Update",
"the",
"context",
"with",
"information",
"from",
"the",
"built",
"packet",
".",
"If",
"no",
"type",
"was",
"given",
"at",
"the",
"record",
"layer",
"we",
"try",
"to",
"infer",
"it",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L161-L186 | train |
secdev/scapy | scapy/layers/tls/record.py | _TLSMsgListField.addfield | def addfield(self, pkt, s, val):
"""
Reconstruct the header because the TLS type may have been updated.
Then, append the content.
"""
res = b""
for p in val:
res += self.i2m(pkt, p)
if (isinstance(pkt, _GenericTLSSessionInheritance) and
_tl... | python | def addfield(self, pkt, s, val):
"""
Reconstruct the header because the TLS type may have been updated.
Then, append the content.
"""
res = b""
for p in val:
res += self.i2m(pkt, p)
if (isinstance(pkt, _GenericTLSSessionInheritance) and
_tl... | [
"def",
"addfield",
"(",
"self",
",",
"pkt",
",",
"s",
",",
"val",
")",
":",
"res",
"=",
"b\"\"",
"for",
"p",
"in",
"val",
":",
"res",
"+=",
"self",
".",
"i2m",
"(",
"pkt",
",",
"p",
")",
"if",
"(",
"isinstance",
"(",
"pkt",
",",
"_GenericTLSSes... | Reconstruct the header because the TLS type may have been updated.
Then, append the content. | [
"Reconstruct",
"the",
"header",
"because",
"the",
"TLS",
"type",
"may",
"have",
"been",
"updated",
".",
"Then",
"append",
"the",
"content",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L188-L203 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS.dispatch_hook | def dispatch_hook(cls, _pkt=None, *args, **kargs):
"""
If the TLS class was called on raw SSLv2 data, we want to return an
SSLv2 record instance. We acknowledge the risk of SSLv2 packets with a
msglen of 0x1403, 0x1503, 0x1603 or 0x1703 which will never be casted
as SSLv2 records... | python | def dispatch_hook(cls, _pkt=None, *args, **kargs):
"""
If the TLS class was called on raw SSLv2 data, we want to return an
SSLv2 record instance. We acknowledge the risk of SSLv2 packets with a
msglen of 0x1403, 0x1503, 0x1603 or 0x1703 which will never be casted
as SSLv2 records... | [
"def",
"dispatch_hook",
"(",
"cls",
",",
"_pkt",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"if",
"_pkt",
"and",
"len",
"(",
"_pkt",
")",
">=",
"2",
":",
"byte0",
"=",
"orb",
"(",
"_pkt",
"[",
"0",
"]",
")",
"byte1",
"="... | If the TLS class was called on raw SSLv2 data, we want to return an
SSLv2 record instance. We acknowledge the risk of SSLv2 packets with a
msglen of 0x1403, 0x1503, 0x1603 or 0x1703 which will never be casted
as SSLv2 records but TLS ones instead, but hey, we can't be held
responsible fo... | [
"If",
"the",
"TLS",
"class",
"was",
"called",
"on",
"raw",
"SSLv2",
"data",
"we",
"want",
"to",
"return",
"an",
"SSLv2",
"record",
"instance",
".",
"We",
"acknowledge",
"the",
"risk",
"of",
"SSLv2",
"packets",
"with",
"a",
"msglen",
"of",
"0x1403",
"0x15... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L276-L301 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_hmac_verify | def _tls_hmac_verify(self, hdr, msg, mac):
"""
Provided with the record header, the TLSCompressed.fragment and the
HMAC, return True if the HMAC is correct. If we could not compute the
HMAC because the key was missing, there is no sense in verifying
anything, thus we also return ... | python | def _tls_hmac_verify(self, hdr, msg, mac):
"""
Provided with the record header, the TLSCompressed.fragment and the
HMAC, return True if the HMAC is correct. If we could not compute the
HMAC because the key was missing, there is no sense in verifying
anything, thus we also return ... | [
"def",
"_tls_hmac_verify",
"(",
"self",
",",
"hdr",
",",
"msg",
",",
"mac",
")",
":",
"read_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"self",
".",
"tls_session",
".",
"rcs",
".",
"seq_num",
")",
"self",
".",
"tls_session",
".",
"rcs",
... | Provided with the record header, the TLSCompressed.fragment and the
HMAC, return True if the HMAC is correct. If we could not compute the
HMAC because the key was missing, there is no sense in verifying
anything, thus we also return True.
Meant to be used with a block cipher or a stream... | [
"Provided",
"with",
"the",
"record",
"header",
"the",
"TLSCompressed",
".",
"fragment",
"and",
"the",
"HMAC",
"return",
"True",
"if",
"the",
"HMAC",
"is",
"correct",
".",
"If",
"we",
"could",
"not",
"compute",
"the",
"HMAC",
"because",
"the",
"key",
"was",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L339-L370 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_decompress | def _tls_decompress(self, s):
"""
Provided with the TLSCompressed.fragment,
return the TLSPlaintext.fragment.
"""
alg = self.tls_session.rcs.compression
return alg.decompress(s) | python | def _tls_decompress(self, s):
"""
Provided with the TLSCompressed.fragment,
return the TLSPlaintext.fragment.
"""
alg = self.tls_session.rcs.compression
return alg.decompress(s) | [
"def",
"_tls_decompress",
"(",
"self",
",",
"s",
")",
":",
"alg",
"=",
"self",
".",
"tls_session",
".",
"rcs",
".",
"compression",
"return",
"alg",
".",
"decompress",
"(",
"s",
")"
] | Provided with the TLSCompressed.fragment,
return the TLSPlaintext.fragment. | [
"Provided",
"with",
"the",
"TLSCompressed",
".",
"fragment",
"return",
"the",
"TLSPlaintext",
".",
"fragment",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L372-L378 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS.pre_dissect | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message,
i.e. apply the previous methods according to the reading cipher type.
If the decryption was successful, 'len' will be the length of the
TLSPlaintext.fragment. Else, it should be the length of the
_T... | python | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message,
i.e. apply the previous methods according to the reading cipher type.
If the decryption was successful, 'len' will be the length of the
TLSPlaintext.fragment. Else, it should be the length of the
_T... | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"<",
"5",
":",
"raise",
"Exception",
"(",
"\"Invalid record: header is too short.\"",
")",
"msglen",
"=",
"struct",
".",
"unpack",
"(",
"'!H'",
",",
"s",
"[",
"3",
":",
... | Decrypt, verify and decompress the message,
i.e. apply the previous methods according to the reading cipher type.
If the decryption was successful, 'len' will be the length of the
TLSPlaintext.fragment. Else, it should be the length of the
_TLSEncryptedContent. | [
"Decrypt",
"verify",
"and",
"decompress",
"the",
"message",
"i",
".",
"e",
".",
"apply",
"the",
"previous",
"methods",
"according",
"to",
"the",
"reading",
"cipher",
"type",
".",
"If",
"the",
"decryption",
"was",
"successful",
"len",
"will",
"be",
"the",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L380-L496 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS.post_dissect | def post_dissect(self, s):
"""
Commit the pending r/w state if it has been triggered (e.g. by an
underlying TLSChangeCipherSpec or a SSLv2ClientMasterKey). We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the... | python | def post_dissect(self, s):
"""
Commit the pending r/w state if it has been triggered (e.g. by an
underlying TLSChangeCipherSpec or a SSLv2ClientMasterKey). We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the... | [
"def",
"post_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"self",
".",
"tls_session",
".",
"triggered_prcs_commit",
":",
"if",
"self",
".",
"tls_session",
".",
"prcs",
"is",
"not",
"None",
":",
"self",
".",
"tls_session",
".",
"rcs",
"=",
"self",
"... | Commit the pending r/w state if it has been triggered (e.g. by an
underlying TLSChangeCipherSpec or a SSLv2ClientMasterKey). We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs). | [
"Commit",
"the",
"pending",
"r",
"/",
"w",
"state",
"if",
"it",
"has",
"been",
"triggered",
"(",
"e",
".",
"g",
".",
"by",
"an",
"underlying",
"TLSChangeCipherSpec",
"or",
"a",
"SSLv2ClientMasterKey",
")",
".",
"We",
"update",
"nothing",
"if",
"the",
"pr... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L498-L515 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_compress | def _tls_compress(self, s):
"""
Provided with the TLSPlaintext.fragment,
return the TLSCompressed.fragment.
"""
alg = self.tls_session.wcs.compression
return alg.compress(s) | python | def _tls_compress(self, s):
"""
Provided with the TLSPlaintext.fragment,
return the TLSCompressed.fragment.
"""
alg = self.tls_session.wcs.compression
return alg.compress(s) | [
"def",
"_tls_compress",
"(",
"self",
",",
"s",
")",
":",
"alg",
"=",
"self",
".",
"tls_session",
".",
"wcs",
".",
"compression",
"return",
"alg",
".",
"compress",
"(",
"s",
")"
] | Provided with the TLSPlaintext.fragment,
return the TLSCompressed.fragment. | [
"Provided",
"with",
"the",
"TLSPlaintext",
".",
"fragment",
"return",
"the",
"TLSCompressed",
".",
"fragment",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L535-L541 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_auth_encrypt | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.fragment for AEAD ciphers, i.e. the whole
GenericAEADCipher. Also, the additional data is computed right here.
"""
write_seq_num = struct.pack("!Q", self.tls_session.wcs.seq_num)
self.tls_session.wcs.seq_num += ... | python | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.fragment for AEAD ciphers, i.e. the whole
GenericAEADCipher. Also, the additional data is computed right here.
"""
write_seq_num = struct.pack("!Q", self.tls_session.wcs.seq_num)
self.tls_session.wcs.seq_num += ... | [
"def",
"_tls_auth_encrypt",
"(",
"self",
",",
"s",
")",
":",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"self",
".",
"tls_session",
".",
"wcs",
".",
"seq_num",
")",
"self",
".",
"tls_session",
".",
"wcs",
".",
"seq_num",
"+=",
"1"... | Return the TLSCiphertext.fragment for AEAD ciphers, i.e. the whole
GenericAEADCipher. Also, the additional data is computed right here. | [
"Return",
"the",
"TLSCiphertext",
".",
"fragment",
"for",
"AEAD",
"ciphers",
"i",
".",
"e",
".",
"the",
"whole",
"GenericAEADCipher",
".",
"Also",
"the",
"additional",
"data",
"is",
"computed",
"right",
"here",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L543-L555 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_hmac_add | def _tls_hmac_add(self, hdr, msg):
"""
Provided with the record header (concatenation of the TLSCompressed
type, version and length fields) and the TLSCompressed.fragment,
return the concatenation of the TLSCompressed.fragment and the HMAC.
Meant to be used with a block cipher o... | python | def _tls_hmac_add(self, hdr, msg):
"""
Provided with the record header (concatenation of the TLSCompressed
type, version and length fields) and the TLSCompressed.fragment,
return the concatenation of the TLSCompressed.fragment and the HMAC.
Meant to be used with a block cipher o... | [
"def",
"_tls_hmac_add",
"(",
"self",
",",
"hdr",
",",
"msg",
")",
":",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"self",
".",
"tls_session",
".",
"wcs",
".",
"seq_num",
")",
"self",
".",
"tls_session",
".",
"wcs",
".",
"seq_num",... | Provided with the record header (concatenation of the TLSCompressed
type, version and length fields) and the TLSCompressed.fragment,
return the concatenation of the TLSCompressed.fragment and the HMAC.
Meant to be used with a block cipher or a stream cipher.
It would fail with an AEAD c... | [
"Provided",
"with",
"the",
"record",
"header",
"(",
"concatenation",
"of",
"the",
"TLSCompressed",
"type",
"version",
"and",
"length",
"fields",
")",
"and",
"the",
"TLSCompressed",
".",
"fragment",
"return",
"the",
"concatenation",
"of",
"the",
"TLSCompressed",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L557-L578 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS._tls_pad | def _tls_pad(self, s):
"""
Provided with the concatenation of the TLSCompressed.fragment and the
HMAC, append the right padding and return it as a whole.
This is the TLS-style padding: while SSL allowed for random padding,
TLS (misguidedly) specifies the repetition of the same by... | python | def _tls_pad(self, s):
"""
Provided with the concatenation of the TLSCompressed.fragment and the
HMAC, append the right padding and return it as a whole.
This is the TLS-style padding: while SSL allowed for random padding,
TLS (misguidedly) specifies the repetition of the same by... | [
"def",
"_tls_pad",
"(",
"self",
",",
"s",
")",
":",
"padding",
"=",
"b\"\"",
"block_size",
"=",
"self",
".",
"tls_session",
".",
"wcs",
".",
"cipher",
".",
"block_size",
"padlen",
"=",
"block_size",
"-",
"(",
"(",
"len",
"(",
"s",
")",
"+",
"1",
")... | Provided with the concatenation of the TLSCompressed.fragment and the
HMAC, append the right padding and return it as a whole.
This is the TLS-style padding: while SSL allowed for random padding,
TLS (misguidedly) specifies the repetition of the same byte all over,
and this byte must be ... | [
"Provided",
"with",
"the",
"concatenation",
"of",
"the",
"TLSCompressed",
".",
"fragment",
"and",
"the",
"HMAC",
"append",
"the",
"right",
"padding",
"and",
"return",
"it",
"as",
"a",
"whole",
".",
"This",
"is",
"the",
"TLS",
"-",
"style",
"padding",
":",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L580-L597 | train |
secdev/scapy | scapy/layers/tls/record.py | TLS.post_build | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
tmp_len = len(frag)
hdr = hdr[:3] + struct.pack("!H", tmp_len)
# Compressio... | python | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
tmp_len = len(frag)
hdr = hdr[:3] + struct.pack("!H", tmp_len)
# Compressio... | [
"def",
"post_build",
"(",
"self",
",",
"pkt",
",",
"pay",
")",
":",
"# Compute the length of TLSPlaintext fragment",
"hdr",
",",
"frag",
"=",
"pkt",
"[",
":",
"5",
"]",
",",
"pkt",
"[",
"5",
":",
"]",
"tmp_len",
"=",
"len",
"(",
"frag",
")",
"hdr",
"... | Apply the previous methods according to the writing cipher type. | [
"Apply",
"the",
"previous",
"methods",
"according",
"to",
"the",
"writing",
"cipher",
"type",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record.py#L607-L676 | train |
secdev/scapy | scapy/supersocket.py | SuperSocket.select | def select(sockets, remain=conf.recv_poll_rate):
"""This function is called during sendrecv() routine to select
the available sockets.
params:
- sockets: an array of sockets that need to be selected
returns:
- an array of sockets that were selected
- the funct... | python | def select(sockets, remain=conf.recv_poll_rate):
"""This function is called during sendrecv() routine to select
the available sockets.
params:
- sockets: an array of sockets that need to be selected
returns:
- an array of sockets that were selected
- the funct... | [
"def",
"select",
"(",
"sockets",
",",
"remain",
"=",
"conf",
".",
"recv_poll_rate",
")",
":",
"try",
":",
"inp",
",",
"_",
",",
"_",
"=",
"select",
"(",
"sockets",
",",
"[",
"]",
",",
"[",
"]",
",",
"remain",
")",
"except",
"(",
"IOError",
",",
... | This function is called during sendrecv() routine to select
the available sockets.
params:
- sockets: an array of sockets that need to be selected
returns:
- an array of sockets that were selected
- the function to be called next to get the packets (i.g. recv) | [
"This",
"function",
"is",
"called",
"during",
"sendrecv",
"()",
"routine",
"to",
"select",
"the",
"available",
"sockets",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/supersocket.py#L109-L125 | train |
secdev/scapy | scapy/supersocket.py | TunTapInterface.open | def open(self):
"""Open the TUN or TAP device."""
if not self.closed:
return
self.outs = self.ins = open(
"/dev/net/tun" if LINUX else ("/dev/%s" % self.iface), "r+b",
buffering=0
)
if LINUX:
from fcntl import ioctl
# TU... | python | def open(self):
"""Open the TUN or TAP device."""
if not self.closed:
return
self.outs = self.ins = open(
"/dev/net/tun" if LINUX else ("/dev/%s" % self.iface), "r+b",
buffering=0
)
if LINUX:
from fcntl import ioctl
# TU... | [
"def",
"open",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"closed",
":",
"return",
"self",
".",
"outs",
"=",
"self",
".",
"ins",
"=",
"open",
"(",
"\"/dev/net/tun\"",
"if",
"LINUX",
"else",
"(",
"\"/dev/%s\"",
"%",
"self",
".",
"iface",
")",
... | Open the TUN or TAP device. | [
"Open",
"the",
"TUN",
"or",
"TAP",
"device",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/supersocket.py#L309-L327 | train |
secdev/scapy | scapy/layers/zigbee.py | util_mic_len | def util_mic_len(pkt):
''' Calculate the length of the attribute value field '''
if (pkt.nwk_seclevel == 0): # no encryption, no mic
return 0
elif (pkt.nwk_seclevel == 1): # MIC-32
return 4
elif (pkt.nwk_seclevel == 2): # MIC-64
return 8
elif (pkt.nwk_seclevel == 3): # MI... | python | def util_mic_len(pkt):
''' Calculate the length of the attribute value field '''
if (pkt.nwk_seclevel == 0): # no encryption, no mic
return 0
elif (pkt.nwk_seclevel == 1): # MIC-32
return 4
elif (pkt.nwk_seclevel == 2): # MIC-64
return 8
elif (pkt.nwk_seclevel == 3): # MI... | [
"def",
"util_mic_len",
"(",
"pkt",
")",
":",
"if",
"(",
"pkt",
".",
"nwk_seclevel",
"==",
"0",
")",
":",
"# no encryption, no mic",
"return",
"0",
"elif",
"(",
"pkt",
".",
"nwk_seclevel",
"==",
"1",
")",
":",
"# MIC-32",
"return",
"4",
"elif",
"(",
"pk... | Calculate the length of the attribute value field | [
"Calculate",
"the",
"length",
"of",
"the",
"attribute",
"value",
"field"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/zigbee.py#L460-L479 | train |
secdev/scapy | scapy/contrib/eddystone.py | Eddystone_Frame.build_eir | def build_eir(self):
"""Builds a list of EIR messages to wrap this frame."""
return LowEnergyBeaconHelper.base_eir + [
EIR_Hdr() / EIR_CompleteList16BitServiceUUIDs(svc_uuids=[
EDDYSTONE_UUID]),
EIR_Hdr() / EIR_ServiceData16BitUUID() / self
] | python | def build_eir(self):
"""Builds a list of EIR messages to wrap this frame."""
return LowEnergyBeaconHelper.base_eir + [
EIR_Hdr() / EIR_CompleteList16BitServiceUUIDs(svc_uuids=[
EDDYSTONE_UUID]),
EIR_Hdr() / EIR_ServiceData16BitUUID() / self
] | [
"def",
"build_eir",
"(",
"self",
")",
":",
"return",
"LowEnergyBeaconHelper",
".",
"base_eir",
"+",
"[",
"EIR_Hdr",
"(",
")",
"/",
"EIR_CompleteList16BitServiceUUIDs",
"(",
"svc_uuids",
"=",
"[",
"EDDYSTONE_UUID",
"]",
")",
",",
"EIR_Hdr",
"(",
")",
"/",
"EI... | Builds a list of EIR messages to wrap this frame. | [
"Builds",
"a",
"list",
"of",
"EIR",
"messages",
"to",
"wrap",
"this",
"frame",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/eddystone.py#L117-L124 | train |
secdev/scapy | scapy/contrib/eddystone.py | Eddystone_URL.from_url | def from_url(url):
"""Creates an Eddystone_Frame with a Eddystone_URL for a given URL."""
url = url.encode('ascii')
scheme = None
for k, v in EDDYSTONE_URL_SCHEMES.items():
if url.startswith(v):
scheme = k
url = url[len(v):]
bre... | python | def from_url(url):
"""Creates an Eddystone_Frame with a Eddystone_URL for a given URL."""
url = url.encode('ascii')
scheme = None
for k, v in EDDYSTONE_URL_SCHEMES.items():
if url.startswith(v):
scheme = k
url = url[len(v):]
bre... | [
"def",
"from_url",
"(",
"url",
")",
":",
"url",
"=",
"url",
".",
"encode",
"(",
"'ascii'",
")",
"scheme",
"=",
"None",
"for",
"k",
",",
"v",
"in",
"EDDYSTONE_URL_SCHEMES",
".",
"items",
"(",
")",
":",
"if",
"url",
".",
"startswith",
"(",
"v",
")",
... | Creates an Eddystone_Frame with a Eddystone_URL for a given URL. | [
"Creates",
"an",
"Eddystone_Frame",
"with",
"a",
"Eddystone_URL",
"for",
"a",
"given",
"URL",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/eddystone.py#L159-L173 | train |
secdev/scapy | scapy/route6.py | Route6.add | def add(self, *args, **kargs):
"""Ex:
add(dst="2001:db8:cafe:f000::/56")
add(dst="2001:db8:cafe:f000::/56", gw="2001:db8:cafe::1")
add(dst="2001:db8:cafe:f000::/64", gw="2001:db8:cafe::1", dev="eth0")
"""
self.invalidate_cache()
self.routes.append(self.make_route(... | python | def add(self, *args, **kargs):
"""Ex:
add(dst="2001:db8:cafe:f000::/56")
add(dst="2001:db8:cafe:f000::/56", gw="2001:db8:cafe::1")
add(dst="2001:db8:cafe:f000::/64", gw="2001:db8:cafe::1", dev="eth0")
"""
self.invalidate_cache()
self.routes.append(self.make_route(... | [
"def",
"add",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"self",
".",
"invalidate_cache",
"(",
")",
"self",
".",
"routes",
".",
"append",
"(",
"self",
".",
"make_route",
"(",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
")"
] | Ex:
add(dst="2001:db8:cafe:f000::/56")
add(dst="2001:db8:cafe:f000::/56", gw="2001:db8:cafe::1")
add(dst="2001:db8:cafe:f000::/64", gw="2001:db8:cafe::1", dev="eth0") | [
"Ex",
":",
"add",
"(",
"dst",
"=",
"2001",
":",
"db8",
":",
"cafe",
":",
"f000",
"::",
"/",
"56",
")",
"add",
"(",
"dst",
"=",
"2001",
":",
"db8",
":",
"cafe",
":",
"f000",
"::",
"/",
"56",
"gw",
"=",
"2001",
":",
"db8",
":",
"cafe",
"::",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/route6.py#L91-L98 | train |
secdev/scapy | scapy/route6.py | Route6.ifdel | def ifdel(self, iff):
""" removes all route entries that uses 'iff' interface. """
new_routes = []
for rt in self.routes:
if rt[3] != iff:
new_routes.append(rt)
self.invalidate_cache()
self.routes = new_routes | python | def ifdel(self, iff):
""" removes all route entries that uses 'iff' interface. """
new_routes = []
for rt in self.routes:
if rt[3] != iff:
new_routes.append(rt)
self.invalidate_cache()
self.routes = new_routes | [
"def",
"ifdel",
"(",
"self",
",",
"iff",
")",
":",
"new_routes",
"=",
"[",
"]",
"for",
"rt",
"in",
"self",
".",
"routes",
":",
"if",
"rt",
"[",
"3",
"]",
"!=",
"iff",
":",
"new_routes",
".",
"append",
"(",
"rt",
")",
"self",
".",
"invalidate_cach... | removes all route entries that uses 'iff' interface. | [
"removes",
"all",
"route",
"entries",
"that",
"uses",
"iff",
"interface",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/route6.py#L143-L150 | train |
secdev/scapy | scapy/route6.py | Route6.ifadd | def ifadd(self, iff, addr):
"""
Add an interface 'iff' with provided address into routing table.
Ex: ifadd('eth0', '2001:bd8:cafe:1::1/64') will add following entry into # noqa: E501
Scapy6 internal routing table:
Destination Next Hop iface Def src @ ... | python | def ifadd(self, iff, addr):
"""
Add an interface 'iff' with provided address into routing table.
Ex: ifadd('eth0', '2001:bd8:cafe:1::1/64') will add following entry into # noqa: E501
Scapy6 internal routing table:
Destination Next Hop iface Def src @ ... | [
"def",
"ifadd",
"(",
"self",
",",
"iff",
",",
"addr",
")",
":",
"addr",
",",
"plen",
"=",
"(",
"addr",
".",
"split",
"(",
"\"/\"",
")",
"+",
"[",
"\"128\"",
"]",
")",
"[",
":",
"2",
"]",
"addr",
"=",
"in6_ptop",
"(",
"addr",
")",
"plen",
"=",... | Add an interface 'iff' with provided address into routing table.
Ex: ifadd('eth0', '2001:bd8:cafe:1::1/64') will add following entry into # noqa: E501
Scapy6 internal routing table:
Destination Next Hop iface Def src @ Metric
2001:bd8:cafe:1::/64 :: ... | [
"Add",
"an",
"interface",
"iff",
"with",
"provided",
"address",
"into",
"routing",
"table",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/route6.py#L152-L172 | train |
secdev/scapy | scapy/route6.py | Route6.route | def route(self, dst=None, dev=None, verbose=conf.verb):
"""
Provide best route to IPv6 destination address, based on Scapy
internal routing table content.
When a set of address is passed (e.g. 2001:db8:cafe:*::1-5) an address
of the set is used. Be aware of that behavior when us... | python | def route(self, dst=None, dev=None, verbose=conf.verb):
"""
Provide best route to IPv6 destination address, based on Scapy
internal routing table content.
When a set of address is passed (e.g. 2001:db8:cafe:*::1-5) an address
of the set is used. Be aware of that behavior when us... | [
"def",
"route",
"(",
"self",
",",
"dst",
"=",
"None",
",",
"dev",
"=",
"None",
",",
"verbose",
"=",
"conf",
".",
"verb",
")",
":",
"dst",
"=",
"dst",
"or",
"\"::/0\"",
"# Enable route(None) to return default route",
"# Transform \"2001:db8:cafe:*::1-5:0/120\" to o... | Provide best route to IPv6 destination address, based on Scapy
internal routing table content.
When a set of address is passed (e.g. 2001:db8:cafe:*::1-5) an address
of the set is used. Be aware of that behavior when using wildcards in
upper parts of addresses !
If 'dst' parame... | [
"Provide",
"best",
"route",
"to",
"IPv6",
"destination",
"address",
"based",
"on",
"Scapy",
"internal",
"routing",
"table",
"content",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/route6.py#L174-L282 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_compress | def _tls_compress(alg, p):
"""
Compress p (a TLSPlaintext instance) using compression algorithm instance
alg and return a TLSCompressed instance.
"""
c = TLSCompressed()
c.type = p.type
c.version = p.version
c.data = alg.compress(p.data)
c.len = len(c.data)
return c | python | def _tls_compress(alg, p):
"""
Compress p (a TLSPlaintext instance) using compression algorithm instance
alg and return a TLSCompressed instance.
"""
c = TLSCompressed()
c.type = p.type
c.version = p.version
c.data = alg.compress(p.data)
c.len = len(c.data)
return c | [
"def",
"_tls_compress",
"(",
"alg",
",",
"p",
")",
":",
"c",
"=",
"TLSCompressed",
"(",
")",
"c",
".",
"type",
"=",
"p",
".",
"type",
"c",
".",
"version",
"=",
"p",
".",
"version",
"c",
".",
"data",
"=",
"alg",
".",
"compress",
"(",
"p",
".",
... | Compress p (a TLSPlaintext instance) using compression algorithm instance
alg and return a TLSCompressed instance. | [
"Compress",
"p",
"(",
"a",
"TLSPlaintext",
"instance",
")",
"using",
"compression",
"algorithm",
"instance",
"alg",
"and",
"return",
"a",
"TLSCompressed",
"instance",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L39-L49 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_decompress | def _tls_decompress(alg, c):
"""
Decompress c (a TLSCompressed instance) using compression algorithm
instance alg and return a TLSPlaintext instance.
"""
p = TLSPlaintext()
p.type = c.type
p.version = c.version
p.data = alg.decompress(c.data)
p.len = len(p.data)
return p | python | def _tls_decompress(alg, c):
"""
Decompress c (a TLSCompressed instance) using compression algorithm
instance alg and return a TLSPlaintext instance.
"""
p = TLSPlaintext()
p.type = c.type
p.version = c.version
p.data = alg.decompress(c.data)
p.len = len(p.data)
return p | [
"def",
"_tls_decompress",
"(",
"alg",
",",
"c",
")",
":",
"p",
"=",
"TLSPlaintext",
"(",
")",
"p",
".",
"type",
"=",
"c",
".",
"type",
"p",
".",
"version",
"=",
"c",
".",
"version",
"p",
".",
"data",
"=",
"alg",
".",
"decompress",
"(",
"c",
"."... | Decompress c (a TLSCompressed instance) using compression algorithm
instance alg and return a TLSPlaintext instance. | [
"Decompress",
"c",
"(",
"a",
"TLSCompressed",
"instance",
")",
"using",
"compression",
"algorithm",
"instance",
"alg",
"and",
"return",
"a",
"TLSPlaintext",
"instance",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L52-L62 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_mac_add | def _tls_mac_add(alg, c, write_seq_num):
"""
Compute the MAC using provided MAC alg instance over TLSCiphertext c using
current write sequence number write_seq_num. Computed MAC is then appended
to c.data and c.len is updated to reflect that change. It is the
caller responsibility to increment the s... | python | def _tls_mac_add(alg, c, write_seq_num):
"""
Compute the MAC using provided MAC alg instance over TLSCiphertext c using
current write sequence number write_seq_num. Computed MAC is then appended
to c.data and c.len is updated to reflect that change. It is the
caller responsibility to increment the s... | [
"def",
"_tls_mac_add",
"(",
"alg",
",",
"c",
",",
"write_seq_num",
")",
":",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"write_seq_num",
")",
"h",
"=",
"alg",
".",
"digest",
"(",
"write_seq_num",
"+",
"bytes",
"(",
"c",
")",
")",
... | Compute the MAC using provided MAC alg instance over TLSCiphertext c using
current write sequence number write_seq_num. Computed MAC is then appended
to c.data and c.len is updated to reflect that change. It is the
caller responsibility to increment the sequence number after the operation.
The function ... | [
"Compute",
"the",
"MAC",
"using",
"provided",
"MAC",
"alg",
"instance",
"over",
"TLSCiphertext",
"c",
"using",
"current",
"write",
"sequence",
"number",
"write_seq_num",
".",
"Computed",
"MAC",
"is",
"then",
"appended",
"to",
"c",
".",
"data",
"and",
"c",
".... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L65-L76 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_mac_verify | def _tls_mac_verify(alg, p, read_seq_num):
"""
Verify if the MAC in provided message (message resulting from decryption
and padding removal) is valid. Current read sequence number is used in
the verification process.
If the MAC is valid:
- The function returns True
- The packet p is updat... | python | def _tls_mac_verify(alg, p, read_seq_num):
"""
Verify if the MAC in provided message (message resulting from decryption
and padding removal) is valid. Current read sequence number is used in
the verification process.
If the MAC is valid:
- The function returns True
- The packet p is updat... | [
"def",
"_tls_mac_verify",
"(",
"alg",
",",
"p",
",",
"read_seq_num",
")",
":",
"h_size",
"=",
"alg",
".",
"hash_len",
"if",
"p",
".",
"len",
"<",
"h_size",
":",
"return",
"False",
"received_h",
"=",
"p",
".",
"data",
"[",
"-",
"h_size",
":",
"]",
"... | Verify if the MAC in provided message (message resulting from decryption
and padding removal) is valid. Current read sequence number is used in
the verification process.
If the MAC is valid:
- The function returns True
- The packet p is updated in the following way: trailing MAC value is
r... | [
"Verify",
"if",
"the",
"MAC",
"in",
"provided",
"message",
"(",
"message",
"resulting",
"from",
"decryption",
"and",
"padding",
"removal",
")",
"is",
"valid",
".",
"Current",
"read",
"sequence",
"number",
"is",
"used",
"in",
"the",
"verification",
"process",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L79-L104 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_add_pad | def _tls_add_pad(p, block_size):
"""
Provided with cipher block size parameter and current TLSCompressed packet
p (after MAC addition), the function adds required, deterministic padding
to p.data before encryption step, as it is defined for TLS (i.e. not
SSL and its allowed random padding). The func... | python | def _tls_add_pad(p, block_size):
"""
Provided with cipher block size parameter and current TLSCompressed packet
p (after MAC addition), the function adds required, deterministic padding
to p.data before encryption step, as it is defined for TLS (i.e. not
SSL and its allowed random padding). The func... | [
"def",
"_tls_add_pad",
"(",
"p",
",",
"block_size",
")",
":",
"padlen",
"=",
"-",
"p",
".",
"len",
"%",
"block_size",
"padding",
"=",
"chb",
"(",
"padlen",
")",
"*",
"(",
"padlen",
"+",
"1",
")",
"p",
".",
"len",
"+=",
"len",
"(",
"padding",
")",... | Provided with cipher block size parameter and current TLSCompressed packet
p (after MAC addition), the function adds required, deterministic padding
to p.data before encryption step, as it is defined for TLS (i.e. not
SSL and its allowed random padding). The function has no return value. | [
"Provided",
"with",
"cipher",
"block",
"size",
"parameter",
"and",
"current",
"TLSCompressed",
"packet",
"p",
"(",
"after",
"MAC",
"addition",
")",
"the",
"function",
"adds",
"required",
"deterministic",
"padding",
"to",
"p",
".",
"data",
"before",
"encryption",... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L107-L117 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_del_pad | def _tls_del_pad(p):
"""
Provided with a just decrypted TLSCiphertext (now a TLSPlaintext instance)
p, the function removes the trailing padding found in p.data. It also
performs some sanity checks on the padding (length, content, ...). False
is returned if one of the check fails. Otherwise, True is... | python | def _tls_del_pad(p):
"""
Provided with a just decrypted TLSCiphertext (now a TLSPlaintext instance)
p, the function removes the trailing padding found in p.data. It also
performs some sanity checks on the padding (length, content, ...). False
is returned if one of the check fails. Otherwise, True is... | [
"def",
"_tls_del_pad",
"(",
"p",
")",
":",
"if",
"p",
".",
"len",
"<",
"1",
":",
"warning",
"(",
"\"Message format is invalid (padding)\"",
")",
"return",
"False",
"padlen",
"=",
"orb",
"(",
"p",
".",
"data",
"[",
"-",
"1",
"]",
")",
"padsize",
"=",
... | Provided with a just decrypted TLSCiphertext (now a TLSPlaintext instance)
p, the function removes the trailing padding found in p.data. It also
performs some sanity checks on the padding (length, content, ...). False
is returned if one of the check fails. Otherwise, True is returned,
indicating that p.... | [
"Provided",
"with",
"a",
"just",
"decrypted",
"TLSCiphertext",
"(",
"now",
"a",
"TLSPlaintext",
"instance",
")",
"p",
"the",
"function",
"removes",
"the",
"trailing",
"padding",
"found",
"in",
"p",
".",
"data",
".",
"It",
"also",
"performs",
"some",
"sanity"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L120-L147 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_encrypt | def _tls_encrypt(alg, p):
"""
Provided with an already MACed TLSCompressed packet, and a stream or block
cipher alg, the function converts it into a TLSCiphertext (i.e. encrypts it
and updates length). The function returns a newly created TLSCiphertext
instance.
"""
c = TLSCiphertext()
c... | python | def _tls_encrypt(alg, p):
"""
Provided with an already MACed TLSCompressed packet, and a stream or block
cipher alg, the function converts it into a TLSCiphertext (i.e. encrypts it
and updates length). The function returns a newly created TLSCiphertext
instance.
"""
c = TLSCiphertext()
c... | [
"def",
"_tls_encrypt",
"(",
"alg",
",",
"p",
")",
":",
"c",
"=",
"TLSCiphertext",
"(",
")",
"c",
".",
"type",
"=",
"p",
".",
"type",
"c",
".",
"version",
"=",
"p",
".",
"version",
"c",
".",
"data",
"=",
"alg",
".",
"encrypt",
"(",
"p",
".",
"... | Provided with an already MACed TLSCompressed packet, and a stream or block
cipher alg, the function converts it into a TLSCiphertext (i.e. encrypts it
and updates length). The function returns a newly created TLSCiphertext
instance. | [
"Provided",
"with",
"an",
"already",
"MACed",
"TLSCompressed",
"packet",
"and",
"a",
"stream",
"or",
"block",
"cipher",
"alg",
"the",
"function",
"converts",
"it",
"into",
"a",
"TLSCiphertext",
"(",
"i",
".",
"e",
".",
"encrypts",
"it",
"and",
"updates",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L150-L162 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_decrypt | def _tls_decrypt(alg, c):
"""
Provided with a TLSCiphertext instance c, and a stream or block cipher alg,
the function decrypts c.data and returns a newly created TLSPlaintext.
"""
p = TLSPlaintext()
p.type = c.type
p.version = c.version
p.data = alg.decrypt(c.data)
p.len = len(p.dat... | python | def _tls_decrypt(alg, c):
"""
Provided with a TLSCiphertext instance c, and a stream or block cipher alg,
the function decrypts c.data and returns a newly created TLSPlaintext.
"""
p = TLSPlaintext()
p.type = c.type
p.version = c.version
p.data = alg.decrypt(c.data)
p.len = len(p.dat... | [
"def",
"_tls_decrypt",
"(",
"alg",
",",
"c",
")",
":",
"p",
"=",
"TLSPlaintext",
"(",
")",
"p",
".",
"type",
"=",
"c",
".",
"type",
"p",
".",
"version",
"=",
"c",
".",
"version",
"p",
".",
"data",
"=",
"alg",
".",
"decrypt",
"(",
"c",
".",
"d... | Provided with a TLSCiphertext instance c, and a stream or block cipher alg,
the function decrypts c.data and returns a newly created TLSPlaintext. | [
"Provided",
"with",
"a",
"TLSCiphertext",
"instance",
"c",
"and",
"a",
"stream",
"or",
"block",
"cipher",
"alg",
"the",
"function",
"decrypts",
"c",
".",
"data",
"and",
"returns",
"a",
"newly",
"created",
"TLSPlaintext",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L165-L175 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_aead_auth_encrypt | def _tls_aead_auth_encrypt(alg, p, write_seq_num):
"""
Provided with a TLSCompressed instance p, the function applies AEAD
cipher alg to p.data and builds a new TLSCiphertext instance. Unlike
for block and stream ciphers, for which the authentication step is done
separately, AEAD alg does it simulta... | python | def _tls_aead_auth_encrypt(alg, p, write_seq_num):
"""
Provided with a TLSCompressed instance p, the function applies AEAD
cipher alg to p.data and builds a new TLSCiphertext instance. Unlike
for block and stream ciphers, for which the authentication step is done
separately, AEAD alg does it simulta... | [
"def",
"_tls_aead_auth_encrypt",
"(",
"alg",
",",
"p",
",",
"write_seq_num",
")",
":",
"P",
"=",
"bytes",
"(",
"p",
")",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"write_seq_num",
")",
"A",
"=",
"write_seq_num",
"+",
"P",
"[",
":... | Provided with a TLSCompressed instance p, the function applies AEAD
cipher alg to p.data and builds a new TLSCiphertext instance. Unlike
for block and stream ciphers, for which the authentication step is done
separately, AEAD alg does it simultaneously: this is the reason why
write_seq_num is passed to ... | [
"Provided",
"with",
"a",
"TLSCompressed",
"instance",
"p",
"the",
"function",
"applies",
"AEAD",
"cipher",
"alg",
"to",
"p",
".",
"data",
"and",
"builds",
"a",
"new",
"TLSCiphertext",
"instance",
".",
"Unlike",
"for",
"block",
"and",
"stream",
"ciphers",
"fo... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L178-L197 | train |
secdev/scapy | scapy/layers/tls/tools.py | _tls_aead_auth_decrypt | def _tls_aead_auth_decrypt(alg, c, read_seq_num):
"""
Provided with a TLSCiphertext instance c, the function applies AEAD
cipher alg auth_decrypt function to c.data (and additional data)
in order to authenticate the data and decrypt c.data. When those
steps succeed, the result is a newly created TLS... | python | def _tls_aead_auth_decrypt(alg, c, read_seq_num):
"""
Provided with a TLSCiphertext instance c, the function applies AEAD
cipher alg auth_decrypt function to c.data (and additional data)
in order to authenticate the data and decrypt c.data. When those
steps succeed, the result is a newly created TLS... | [
"def",
"_tls_aead_auth_decrypt",
"(",
"alg",
",",
"c",
",",
"read_seq_num",
")",
":",
"# 'Deduce' TLSCompressed length from TLSCiphertext length",
"# There is actually no guaranty of this equality, but this is defined as",
"# such in TLS 1.2 specifications, and it works for GCM and CCM at le... | Provided with a TLSCiphertext instance c, the function applies AEAD
cipher alg auth_decrypt function to c.data (and additional data)
in order to authenticate the data and decrypt c.data. When those
steps succeed, the result is a newly created TLSCompressed instance.
On error, None is returned. Note that... | [
"Provided",
"with",
"a",
"TLSCiphertext",
"instance",
"c",
"the",
"function",
"applies",
"AEAD",
"cipher",
"alg",
"auth_decrypt",
"function",
"to",
"c",
".",
"data",
"(",
"and",
"additional",
"data",
")",
"in",
"order",
"to",
"authenticate",
"the",
"data",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/tools.py#L200-L225 | train |
secdev/scapy | scapy/layers/usb.py | _extcap_call | def _extcap_call(prog, args, keyword, values):
"""Function used to call a program using the extcap format,
then parse the results"""
p = subprocess.Popen(
[prog] + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
data, err = p.communicate()
if p.returncode != 0:
rai... | python | def _extcap_call(prog, args, keyword, values):
"""Function used to call a program using the extcap format,
then parse the results"""
p = subprocess.Popen(
[prog] + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
data, err = p.communicate()
if p.returncode != 0:
rai... | [
"def",
"_extcap_call",
"(",
"prog",
",",
"args",
",",
"keyword",
",",
"values",
")",
":",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"prog",
"]",
"+",
"args",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",
... | Function used to call a program using the extcap format,
then parse the results | [
"Function",
"used",
"to",
"call",
"a",
"program",
"using",
"the",
"extcap",
"format",
"then",
"parse",
"the",
"results"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/usb.py#L156-L176 | train |
secdev/scapy | scapy/contrib/ppi_geotag.py | _hcsi_null_range | def _hcsi_null_range(*args, **kwargs):
"""Builds a list of _HCSINullField with numbered "Reserved" names.
Takes the same arguments as the ``range`` built-in.
:returns: list[HCSINullField]
"""
return [
HCSINullField('Reserved{:02d}'.format(x))
for x in range(*args, **kwargs)
] | python | def _hcsi_null_range(*args, **kwargs):
"""Builds a list of _HCSINullField with numbered "Reserved" names.
Takes the same arguments as the ``range`` built-in.
:returns: list[HCSINullField]
"""
return [
HCSINullField('Reserved{:02d}'.format(x))
for x in range(*args, **kwargs)
] | [
"def",
"_hcsi_null_range",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"HCSINullField",
"(",
"'Reserved{:02d}'",
".",
"format",
"(",
"x",
")",
")",
"for",
"x",
"in",
"range",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"... | Builds a list of _HCSINullField with numbered "Reserved" names.
Takes the same arguments as the ``range`` built-in.
:returns: list[HCSINullField] | [
"Builds",
"a",
"list",
"of",
"_HCSINullField",
"with",
"numbered",
"Reserved",
"names",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/ppi_geotag.py#L243-L253 | train |
secdev/scapy | scapy/contrib/ppi_geotag.py | _RMMLEIntField.i2m | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
# Try to return zero if undefined
x = self.h2i(pkt, 0)
return x | python | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
# Try to return zero if undefined
x = self.h2i(pkt, 0)
return x | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"if",
"x",
"is",
"None",
":",
"# Try to return zero if undefined",
"x",
"=",
"self",
".",
"h2i",
"(",
"pkt",
",",
"0",
")",
"return",
"x"
] | Convert internal value to machine value | [
"Convert",
"internal",
"value",
"to",
"machine",
"value"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/ppi_geotag.py#L86-L91 | train |
secdev/scapy | scapy/arch/__init__.py | get_if_addr6 | def get_if_addr6(iff):
"""
Returns the main global unicast address associated with provided
interface, in human readable form. If no global address is found,
None is returned.
"""
return next((x[0] for x in in6_getifaddr()
if x[2] == iff and x[1] == IPV6_ADDR_GLOBAL), None) | python | def get_if_addr6(iff):
"""
Returns the main global unicast address associated with provided
interface, in human readable form. If no global address is found,
None is returned.
"""
return next((x[0] for x in in6_getifaddr()
if x[2] == iff and x[1] == IPV6_ADDR_GLOBAL), None) | [
"def",
"get_if_addr6",
"(",
"iff",
")",
":",
"return",
"next",
"(",
"(",
"x",
"[",
"0",
"]",
"for",
"x",
"in",
"in6_getifaddr",
"(",
")",
"if",
"x",
"[",
"2",
"]",
"==",
"iff",
"and",
"x",
"[",
"1",
"]",
"==",
"IPV6_ADDR_GLOBAL",
")",
",",
"Non... | Returns the main global unicast address associated with provided
interface, in human readable form. If no global address is found,
None is returned. | [
"Returns",
"the",
"main",
"global",
"unicast",
"address",
"associated",
"with",
"provided",
"interface",
"in",
"human",
"readable",
"form",
".",
"If",
"no",
"global",
"address",
"is",
"found",
"None",
"is",
"returned",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/arch/__init__.py#L76-L83 | train |
secdev/scapy | scapy/arch/__init__.py | get_if_raw_addr6 | def get_if_raw_addr6(iff):
"""
Returns the main global unicast address associated with provided
interface, in network format. If no global address is found, None
is returned.
"""
ip6 = get_if_addr6(iff)
if ip6 is not None:
return inet_pton(socket.AF_INET6, ip6)
return None | python | def get_if_raw_addr6(iff):
"""
Returns the main global unicast address associated with provided
interface, in network format. If no global address is found, None
is returned.
"""
ip6 = get_if_addr6(iff)
if ip6 is not None:
return inet_pton(socket.AF_INET6, ip6)
return None | [
"def",
"get_if_raw_addr6",
"(",
"iff",
")",
":",
"ip6",
"=",
"get_if_addr6",
"(",
"iff",
")",
"if",
"ip6",
"is",
"not",
"None",
":",
"return",
"inet_pton",
"(",
"socket",
".",
"AF_INET6",
",",
"ip6",
")",
"return",
"None"
] | Returns the main global unicast address associated with provided
interface, in network format. If no global address is found, None
is returned. | [
"Returns",
"the",
"main",
"global",
"unicast",
"address",
"associated",
"with",
"provided",
"interface",
"in",
"network",
"format",
".",
"If",
"no",
"global",
"address",
"is",
"found",
"None",
"is",
"returned",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/arch/__init__.py#L86-L96 | train |
secdev/scapy | scapy/contrib/pnio.py | i2s_frameid | def i2s_frameid(x):
""" Get representation name of a pnio frame ID
:param x: a key of the PNIO_FRAME_IDS dictionary
:returns: str
"""
try:
return PNIO_FRAME_IDS[x]
except KeyError:
pass
if 0x0100 <= x < 0x1000:
return "RT_CLASS_3 (%4x)" % x
if 0x8000 <= x < 0xC00... | python | def i2s_frameid(x):
""" Get representation name of a pnio frame ID
:param x: a key of the PNIO_FRAME_IDS dictionary
:returns: str
"""
try:
return PNIO_FRAME_IDS[x]
except KeyError:
pass
if 0x0100 <= x < 0x1000:
return "RT_CLASS_3 (%4x)" % x
if 0x8000 <= x < 0xC00... | [
"def",
"i2s_frameid",
"(",
"x",
")",
":",
"try",
":",
"return",
"PNIO_FRAME_IDS",
"[",
"x",
"]",
"except",
"KeyError",
":",
"pass",
"if",
"0x0100",
"<=",
"x",
"<",
"0x1000",
":",
"return",
"\"RT_CLASS_3 (%4x)\"",
"%",
"x",
"if",
"0x8000",
"<=",
"x",
"<... | Get representation name of a pnio frame ID
:param x: a key of the PNIO_FRAME_IDS dictionary
:returns: str | [
"Get",
"representation",
"name",
"of",
"a",
"pnio",
"frame",
"ID"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/pnio.py#L53-L71 | train |
secdev/scapy | scapy/contrib/pnio.py | s2i_frameid | def s2i_frameid(x):
""" Get pnio frame ID from a representation name
Performs a reverse look-up in PNIO_FRAME_IDS dictionary
:param x: a value of PNIO_FRAME_IDS dict
:returns: integer
"""
try:
return {
"RT_CLASS_3": 0x0100,
"RT_CLASS_1": 0x8000,
"RT_... | python | def s2i_frameid(x):
""" Get pnio frame ID from a representation name
Performs a reverse look-up in PNIO_FRAME_IDS dictionary
:param x: a value of PNIO_FRAME_IDS dict
:returns: integer
"""
try:
return {
"RT_CLASS_3": 0x0100,
"RT_CLASS_1": 0x8000,
"RT_... | [
"def",
"s2i_frameid",
"(",
"x",
")",
":",
"try",
":",
"return",
"{",
"\"RT_CLASS_3\"",
":",
"0x0100",
",",
"\"RT_CLASS_1\"",
":",
"0x8000",
",",
"\"RT_CLASS_UDP\"",
":",
"0xC000",
",",
"\"FragmentationFrameID\"",
":",
"0xFF80",
",",
"}",
"[",
"x",
"]",
"ex... | Get pnio frame ID from a representation name
Performs a reverse look-up in PNIO_FRAME_IDS dictionary
:param x: a value of PNIO_FRAME_IDS dict
:returns: integer | [
"Get",
"pnio",
"frame",
"ID",
"from",
"a",
"representation",
"name"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/pnio.py#L74-L96 | train |
secdev/scapy | scapy/contrib/rtr.py | RTR.dispatch_hook | def dispatch_hook(cls, _pkt=None, *args, **kargs):
'''
Attribution of correct type depending on version and pdu_type
'''
if _pkt and len(_pkt) >= 2:
version = orb(_pkt[0])
pdu_type = orb(_pkt[1])
if version == 0:
return PDU_CLASS_VERS... | python | def dispatch_hook(cls, _pkt=None, *args, **kargs):
'''
Attribution of correct type depending on version and pdu_type
'''
if _pkt and len(_pkt) >= 2:
version = orb(_pkt[0])
pdu_type = orb(_pkt[1])
if version == 0:
return PDU_CLASS_VERS... | [
"def",
"dispatch_hook",
"(",
"cls",
",",
"_pkt",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"if",
"_pkt",
"and",
"len",
"(",
"_pkt",
")",
">=",
"2",
":",
"version",
"=",
"orb",
"(",
"_pkt",
"[",
"0",
"]",
")",
"pdu_type",
... | Attribution of correct type depending on version and pdu_type | [
"Attribution",
"of",
"correct",
"type",
"depending",
"on",
"version",
"and",
"pdu_type"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/rtr.py#L322-L333 | train |
secdev/scapy | scapy/as_resolvers.py | AS_resolver_cymru.parse | def parse(self, data):
"""Parse bulk cymru data"""
ASNlist = []
for line in data.splitlines()[1:]:
line = plain_str(line)
if "|" not in line:
continue
asn, ip, desc = [elt.strip() for elt in line.split('|')]
if asn == "NA":
... | python | def parse(self, data):
"""Parse bulk cymru data"""
ASNlist = []
for line in data.splitlines()[1:]:
line = plain_str(line)
if "|" not in line:
continue
asn, ip, desc = [elt.strip() for elt in line.split('|')]
if asn == "NA":
... | [
"def",
"parse",
"(",
"self",
",",
"data",
")",
":",
"ASNlist",
"=",
"[",
"]",
"for",
"line",
"in",
"data",
".",
"splitlines",
"(",
")",
"[",
"1",
":",
"]",
":",
"line",
"=",
"plain_str",
"(",
"line",
")",
"if",
"\"|\"",
"not",
"in",
"line",
":"... | Parse bulk cymru data | [
"Parse",
"bulk",
"cymru",
"data"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/as_resolvers.py#L102-L115 | train |
secdev/scapy | scapy/contrib/igmpv3.py | IGMPv3.encode_maxrespcode | def encode_maxrespcode(self):
"""Encode and replace the mrcode value to its IGMPv3 encoded time value if needed, # noqa: E501
as specified in rfc3376#section-4.1.1.
If value < 128, return the value specified. If >= 128, encode as a floating # noqa: E501
point value. Value can be 0 - 3... | python | def encode_maxrespcode(self):
"""Encode and replace the mrcode value to its IGMPv3 encoded time value if needed, # noqa: E501
as specified in rfc3376#section-4.1.1.
If value < 128, return the value specified. If >= 128, encode as a floating # noqa: E501
point value. Value can be 0 - 3... | [
"def",
"encode_maxrespcode",
"(",
"self",
")",
":",
"value",
"=",
"self",
".",
"mrcode",
"if",
"value",
"<",
"128",
":",
"code",
"=",
"value",
"elif",
"value",
">",
"31743",
":",
"code",
"=",
"255",
"else",
":",
"exp",
"=",
"0",
"value",
">>=",
"3"... | Encode and replace the mrcode value to its IGMPv3 encoded time value if needed, # noqa: E501
as specified in rfc3376#section-4.1.1.
If value < 128, return the value specified. If >= 128, encode as a floating # noqa: E501
point value. Value can be 0 - 31744. | [
"Encode",
"and",
"replace",
"the",
"mrcode",
"value",
"to",
"its",
"IGMPv3",
"encoded",
"time",
"value",
"if",
"needed",
"#",
"noqa",
":",
"E501",
"as",
"specified",
"in",
"rfc3376#section",
"-",
"4",
".",
"1",
".",
"1",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/igmpv3.py#L74-L94 | train |
secdev/scapy | scapy/layers/lltd.py | _register_lltd_specific_class | def _register_lltd_specific_class(*attr_types):
"""This can be used as a class decorator; if we want to support Python
2.5, we have to replace
@_register_lltd_specific_class(x[, y[, ...]])
class LLTDAttributeSpecific(LLTDAttribute):
[...]
by
class LLTDAttributeSpecific(LLTDAttribute):
[...]
LLTDAttributeSpec... | python | def _register_lltd_specific_class(*attr_types):
"""This can be used as a class decorator; if we want to support Python
2.5, we have to replace
@_register_lltd_specific_class(x[, y[, ...]])
class LLTDAttributeSpecific(LLTDAttribute):
[...]
by
class LLTDAttributeSpecific(LLTDAttribute):
[...]
LLTDAttributeSpec... | [
"def",
"_register_lltd_specific_class",
"(",
"*",
"attr_types",
")",
":",
"def",
"_register",
"(",
"cls",
")",
":",
"for",
"attr_type",
"in",
"attr_types",
":",
"SPECIFIC_CLASSES",
"[",
"attr_type",
"]",
"=",
"cls",
"type_fld",
"=",
"LLTDAttribute",
".",
"fiel... | This can be used as a class decorator; if we want to support Python
2.5, we have to replace
@_register_lltd_specific_class(x[, y[, ...]])
class LLTDAttributeSpecific(LLTDAttribute):
[...]
by
class LLTDAttributeSpecific(LLTDAttribute):
[...]
LLTDAttributeSpecific = _register_lltd_specific_class(x[, y[, ...]])(
... | [
"This",
"can",
"be",
"used",
"as",
"a",
"class",
"decorator",
";",
"if",
"we",
"want",
"to",
"support",
"Python",
"2",
".",
"5",
"we",
"have",
"to",
"replace"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/lltd.py#L312-L336 | train |
secdev/scapy | scapy/layers/lltd.py | LargeTlvBuilder.parse | def parse(self, plist):
"""Update the builder using the provided `plist`. `plist` can
be either a Packet() or a PacketList().
"""
if not isinstance(plist, PacketList):
plist = PacketList(plist)
for pkt in plist[LLTD]:
if LLTDQueryLargeTlv in pkt:
... | python | def parse(self, plist):
"""Update the builder using the provided `plist`. `plist` can
be either a Packet() or a PacketList().
"""
if not isinstance(plist, PacketList):
plist = PacketList(plist)
for pkt in plist[LLTD]:
if LLTDQueryLargeTlv in pkt:
... | [
"def",
"parse",
"(",
"self",
",",
"plist",
")",
":",
"if",
"not",
"isinstance",
"(",
"plist",
",",
"PacketList",
")",
":",
"plist",
"=",
"PacketList",
"(",
"plist",
")",
"for",
"pkt",
"in",
"plist",
"[",
"LLTD",
"]",
":",
"if",
"LLTDQueryLargeTlv",
"... | Update the builder using the provided `plist`. `plist` can
be either a Packet() or a PacketList(). | [
"Update",
"the",
"builder",
"using",
"the",
"provided",
"plist",
".",
"plist",
"can",
"be",
"either",
"a",
"Packet",
"()",
"or",
"a",
"PacketList",
"()",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/lltd.py#L809-L836 | train |
secdev/scapy | scapy/layers/lltd.py | LargeTlvBuilder.get_data | def get_data(self):
"""Returns a dictionary object, keys are strings "source >
destincation [content type]", and values are the content
fetched, also as a string.
"""
return {key: "".join(chr(byte) for byte in data)
for key, data in six.iteritems(self.data)} | python | def get_data(self):
"""Returns a dictionary object, keys are strings "source >
destincation [content type]", and values are the content
fetched, also as a string.
"""
return {key: "".join(chr(byte) for byte in data)
for key, data in six.iteritems(self.data)} | [
"def",
"get_data",
"(",
"self",
")",
":",
"return",
"{",
"key",
":",
"\"\"",
".",
"join",
"(",
"chr",
"(",
"byte",
")",
"for",
"byte",
"in",
"data",
")",
"for",
"key",
",",
"data",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"data",
")",
"... | Returns a dictionary object, keys are strings "source >
destincation [content type]", and values are the content
fetched, also as a string. | [
"Returns",
"a",
"dictionary",
"object",
"keys",
"are",
"strings",
"source",
">",
"destincation",
"[",
"content",
"type",
"]",
"and",
"values",
"are",
"the",
"content",
"fetched",
"also",
"as",
"a",
"string",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/lltd.py#L838-L845 | train |
secdev/scapy | scapy/pton_ntop.py | _inet6_pton | def _inet6_pton(addr):
"""Convert an IPv6 address from text representation into binary form,
used when socket.inet_pton is not available.
"""
joker_pos = None
result = b""
addr = plain_str(addr)
if addr == '::':
return b'\x00' * 16
if addr.startswith('::'):
addr = addr[1:]
... | python | def _inet6_pton(addr):
"""Convert an IPv6 address from text representation into binary form,
used when socket.inet_pton is not available.
"""
joker_pos = None
result = b""
addr = plain_str(addr)
if addr == '::':
return b'\x00' * 16
if addr.startswith('::'):
addr = addr[1:]
... | [
"def",
"_inet6_pton",
"(",
"addr",
")",
":",
"joker_pos",
"=",
"None",
"result",
"=",
"b\"\"",
"addr",
"=",
"plain_str",
"(",
"addr",
")",
"if",
"addr",
"==",
"'::'",
":",
"return",
"b'\\x00'",
"*",
"16",
"if",
"addr",
".",
"startswith",
"(",
"'::'",
... | Convert an IPv6 address from text representation into binary form,
used when socket.inet_pton is not available. | [
"Convert",
"an",
"IPv6",
"address",
"from",
"text",
"representation",
"into",
"binary",
"form",
"used",
"when",
"socket",
".",
"inet_pton",
"is",
"not",
"available",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/pton_ntop.py#L24-L72 | train |
secdev/scapy | scapy/pton_ntop.py | inet_pton | def inet_pton(af, addr):
"""Convert an IP address from text representation into binary form."""
# Will replace Net/Net6 objects
addr = plain_str(addr)
# Use inet_pton if available
try:
return socket.inet_pton(af, addr)
except AttributeError:
try:
return _INET_PTON[af]... | python | def inet_pton(af, addr):
"""Convert an IP address from text representation into binary form."""
# Will replace Net/Net6 objects
addr = plain_str(addr)
# Use inet_pton if available
try:
return socket.inet_pton(af, addr)
except AttributeError:
try:
return _INET_PTON[af]... | [
"def",
"inet_pton",
"(",
"af",
",",
"addr",
")",
":",
"# Will replace Net/Net6 objects",
"addr",
"=",
"plain_str",
"(",
"addr",
")",
"# Use inet_pton if available",
"try",
":",
"return",
"socket",
".",
"inet_pton",
"(",
"af",
",",
"addr",
")",
"except",
"Attri... | Convert an IP address from text representation into binary form. | [
"Convert",
"an",
"IP",
"address",
"from",
"text",
"representation",
"into",
"binary",
"form",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/pton_ntop.py#L81-L92 | train |
secdev/scapy | scapy/pton_ntop.py | _inet6_ntop | def _inet6_ntop(addr):
"""Convert an IPv6 address from binary form into text representation,
used when socket.inet_pton is not available.
"""
# IPv6 addresses have 128bits (16 bytes)
if len(addr) != 16:
raise ValueError("invalid length of packed IP address string")
# Decode to hex represen... | python | def _inet6_ntop(addr):
"""Convert an IPv6 address from binary form into text representation,
used when socket.inet_pton is not available.
"""
# IPv6 addresses have 128bits (16 bytes)
if len(addr) != 16:
raise ValueError("invalid length of packed IP address string")
# Decode to hex represen... | [
"def",
"_inet6_ntop",
"(",
"addr",
")",
":",
"# IPv6 addresses have 128bits (16 bytes)",
"if",
"len",
"(",
"addr",
")",
"!=",
"16",
":",
"raise",
"ValueError",
"(",
"\"invalid length of packed IP address string\"",
")",
"# Decode to hex representation",
"address",
"=",
... | Convert an IPv6 address from binary form into text representation,
used when socket.inet_pton is not available. | [
"Convert",
"an",
"IPv6",
"address",
"from",
"binary",
"form",
"into",
"text",
"representation",
"used",
"when",
"socket",
".",
"inet_pton",
"is",
"not",
"available",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/pton_ntop.py#L95-L118 | train |
secdev/scapy | scapy/pton_ntop.py | inet_ntop | def inet_ntop(af, addr):
"""Convert an IP address from binary form into text representation."""
# Use inet_ntop if available
addr = bytes_encode(addr)
try:
return socket.inet_ntop(af, addr)
except AttributeError:
try:
return _INET_NTOP[af](addr)
except KeyError:
... | python | def inet_ntop(af, addr):
"""Convert an IP address from binary form into text representation."""
# Use inet_ntop if available
addr = bytes_encode(addr)
try:
return socket.inet_ntop(af, addr)
except AttributeError:
try:
return _INET_NTOP[af](addr)
except KeyError:
... | [
"def",
"inet_ntop",
"(",
"af",
",",
"addr",
")",
":",
"# Use inet_ntop if available",
"addr",
"=",
"bytes_encode",
"(",
"addr",
")",
"try",
":",
"return",
"socket",
".",
"inet_ntop",
"(",
"af",
",",
"addr",
")",
"except",
"AttributeError",
":",
"try",
":",... | Convert an IP address from binary form into text representation. | [
"Convert",
"an",
"IP",
"address",
"from",
"binary",
"form",
"into",
"text",
"representation",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/pton_ntop.py#L127-L137 | train |
secdev/scapy | scapy/arch/pcapdnet.py | _L2pcapdnetSocket.recv_raw | def recv_raw(self, x=MTU):
"""Receives a packet, then returns a tuple containing (cls, pkt_data, time)""" # noqa: E501
ll = self.ins.datalink()
if ll in conf.l2types:
cls = conf.l2types[ll]
else:
cls = conf.default_l2
warning("Unable to guess datalink... | python | def recv_raw(self, x=MTU):
"""Receives a packet, then returns a tuple containing (cls, pkt_data, time)""" # noqa: E501
ll = self.ins.datalink()
if ll in conf.l2types:
cls = conf.l2types[ll]
else:
cls = conf.default_l2
warning("Unable to guess datalink... | [
"def",
"recv_raw",
"(",
"self",
",",
"x",
"=",
"MTU",
")",
":",
"# noqa: E501",
"ll",
"=",
"self",
".",
"ins",
".",
"datalink",
"(",
")",
"if",
"ll",
"in",
"conf",
".",
"l2types",
":",
"cls",
"=",
"conf",
".",
"l2types",
"[",
"ll",
"]",
"else",
... | Receives a packet, then returns a tuple containing (cls, pkt_data, time) | [
"Receives",
"a",
"packet",
"then",
"returns",
"a",
"tuple",
"containing",
"(",
"cls",
"pkt_data",
"time",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/arch/pcapdnet.py#L46-L65 | train |
secdev/scapy | scapy/arch/pcapdnet.py | _L2pcapdnetSocket.nonblock_recv | def nonblock_recv(self):
"""Receives and dissect a packet in non-blocking mode.
Note: on Windows, this won't do anything."""
self.ins.setnonblock(1)
p = self.recv(MTU)
self.ins.setnonblock(0)
return p | python | def nonblock_recv(self):
"""Receives and dissect a packet in non-blocking mode.
Note: on Windows, this won't do anything."""
self.ins.setnonblock(1)
p = self.recv(MTU)
self.ins.setnonblock(0)
return p | [
"def",
"nonblock_recv",
"(",
"self",
")",
":",
"self",
".",
"ins",
".",
"setnonblock",
"(",
"1",
")",
"p",
"=",
"self",
".",
"recv",
"(",
"MTU",
")",
"self",
".",
"ins",
".",
"setnonblock",
"(",
"0",
")",
"return",
"p"
] | Receives and dissect a packet in non-blocking mode.
Note: on Windows, this won't do anything. | [
"Receives",
"and",
"dissect",
"a",
"packet",
"in",
"non",
"-",
"blocking",
"mode",
".",
"Note",
":",
"on",
"Windows",
"this",
"won",
"t",
"do",
"anything",
"."
] | 3ffe757c184017dd46464593a8f80f85abc1e79a | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/arch/pcapdnet.py#L67-L73 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.