本文整理汇总了Python中scapy.all方法的典型用法代码示例。如果您正苦于以下问题:Python scapy.all方法的具体用法?Python scapy.all怎么用?Python scapy.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy
的用法示例。
在下文中一共展示了scapy.all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slugify
# 需要导入模块: import scapy [as 别名]
# 或者: from scapy import all [as 别名]
def slugify(word):
""" update all special characters in string to underscore
Args:
word (`str`): string which you want to convert special characters in the word to underscore
Raise:
Exception
Returns:
word
Example:
>>> dev.api.slugify('Ethernet1/1.100')
Ethernet1_1_100
>>> dev.api.slugify('2020-05-26_14:15:36.555')
2020_05_26_14_15_36_555
"""
return re.sub(r'\W+', '_', word)
示例2: dynamic_diff_create_running_config
# 需要导入模块: import scapy [as 别名]
# 或者: from scapy import all [as 别名]
def dynamic_diff_create_running_config(device, mapping, template, base_config):
""" Creates a merged running config from template dynamic diff with
variables replaced by mapping and merged with base config
Args:
mapping ('dict'): Variable to interface mapping
ex.) {'{{ int_1 }}': 'Ethernet2/1-48', '{{ int_2 }}': 'Ethernet5'}
template ('str'): Content of the dynamic diff template
base_config ('str'): Content of the base config
Raise:
None
Returns:
Config ('str'): The merged running config from template
"""
for variable, value in mapping.items():
template = template.replace(variable, value)
# Remove all end markers if any
template = template.replace('\nend \n', '\n')
template = template.replace('\nend\n', '\n')
if template.endswith('\nend'):
template = template[:-4]
if template.endswith('\nend '):
template = template[:-5]
return '{}{}'.format(template, base_config)
示例3: question_mark_retrieve
# 需要导入模块: import scapy [as 别名]
# 或者: from scapy import all [as 别名]
def question_mark_retrieve(device, cmd, timeout=20, state="enable"):
""" Retrieve output after pressing ? on device
Args:
device (`obj`): Device object
cmd (`str`): Command
timeout (`int`): Timeout in second
state (`str`): Cli state
Returns:
output (`str`): Output
"""
# Create a new state for prompt# cmd
pattern = device.state_machine.get_state(state).pattern
if state == "config":
# then remove all except last line
tmp_cmd = cmd.splitlines()[-1]
pattern_mark = pattern[:-1] + tmp_cmd + pattern[-1]
else:
pattern_mark = pattern[:-1] + cmd + pattern[-1]
prompt = Statement(
pattern=pattern_mark,
action="send(\x03)",
args=None,
loop_continue=True,
continue_timer=False,
)
output = _cli(device, cmd + "?", timeout, prompt)
# Remove sent command
output = output.match_output.replace(cmd, "", 1).replace("^C", "")
output = escape_ansi(output)
return output
示例4: verify_pcap_has_imcp_destination_unreachable
# 需要导入模块: import scapy [as 别名]
# 或者: from scapy import all [as 别名]
def verify_pcap_has_imcp_destination_unreachable(pcap_location,
msg_type=3,
msg_code=0):
""" Verify that the pcap file has messages with imcp destination
unreachable with type and code
Args:
pcap_location ('str'): location of pcap file
msg_type ('int'): pcap message type
msg_code ('int'): pcap message code
Returns:
Boolean if icmp destination reachable message in pcap
"""
try:
import scapy.all
rdpcap = scapy.all.rdpcap
ICMP = scapy.layers.inet.ICMP
ICMPv6 = scapy.layers.inet6._ICMPv6
ICMPv6DestUnreach = scapy.layers.inet6.ICMPv6DestUnreach
except ImportError:
raise ImportError(
'scapy is not installed, please install it by running: '
'pip install scapy') from None
pcap_object = rdpcap(pcap_location)
for packet in pcap_object:
if (packet.haslayer(ICMP) and packet.getlayer(ICMP).type == msg_type
and packet.getlayer(ICMP).code == msg_code):
return True
return False
示例5: verify_pcap_has_imcpv6_destination_unreachable
# 需要导入模块: import scapy [as 别名]
# 或者: from scapy import all [as 别名]
def verify_pcap_has_imcpv6_destination_unreachable(pcap_location,
msg_type=1,
msg_code=3):
""" Verify that the pcap file has messages with imcpv6 destination
unreachable with type and code
Args:
pcap_location ('str'): location of pcap file
msg_type ('int'): pcap message type
msg_code ('int'): pcap message code
Returns:
Boolean if icmpv6 destination reachable message in pcap
"""
try:
import scapy.all
rdpcap = scapy.all.rdpcap
ICMP = scapy.layers.inet.ICMP
ICMPv6 = scapy.layers.inet6._ICMPv6
ICMPv6DestUnreach = scapy.layers.inet6.ICMPv6DestUnreach
except ImportError:
raise ImportError(
'scapy is not installed, please install it by running: '
'pip install scapy') from None
pcap_object = rdpcap(pcap_location)
for packet in pcap_object:
if (packet.haslayer(ICMPv6DestUnreach)
and packet.getlayer(ICMPv6DestUnreach).type == msg_type
and packet.getlayer(ICMPv6DestUnreach).code == msg_code):
return True
return False