Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
88500350
Commit
88500350
authored
7 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for TAP sockets & bridge_and_sniff()
parent
90c59eda
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.appveyor.yml
+1
-1
1 addition, 1 deletion
.appveyor.yml
test/sendsniff.uts
+75
-0
75 additions, 0 deletions
test/sendsniff.uts
with
76 additions
and
1 deletion
.appveyor.yml
+
1
−
1
View file @
88500350
...
...
@@ -29,7 +29,7 @@ test_script:
-
'
del
test\regression.uts'
# Secondary and contrib unit tests
-
'
del
test\bpf.uts
test\linux.uts'
# Don't bother with OS dependent regression tests
-
'
del
test\bpf.uts
test\linux.uts
test\sendsniff.uts
'
# Don't bother with OS dependent regression tests
-
"
%PYTHON%
\\
python
-m
coverage
run
--parallel-mode
bin
\\
UTscapy
-c
test
\\
configs
\\
windows.utsc
||
exit
/b
42"
# TLS unit tests
...
...
This diff is collapsed.
Click to expand it.
test/sendsniff.uts
0 → 100644
+
75
−
0
View file @
88500350
% send, sniff, sr* tests for Scapy
~ netaccess
############
############
+ Bridge using tap interfaces
~ tap linux
= Create two tap interfaces
tap0, tap1 = [TunTapInterface("tap%d" % i, create=True) for i in range(2)]
from threading import Thread
= Run a sniff thread on the tap1 **interface**
t_sniff = Thread(
target=sniff,
kwargs={"iface": "tap1", "count": 5, "prn": Packet.summary,
"lfilter": lambda p: IP in p and p[IP].src == "1.2.3.4"}
)
t_sniff.start()
= Run a bridge_and_sniff thread between the taps **sockets**
t_bridge = Thread(target=bridge_and_sniff, args=(tap0, tap1),
kwargs={"store": False, "count": 5, 'prn': Packet.summary,
"lfilter": lambda p: IP in p and p[IP].src == "1.2.3.4"})
t_bridge.start()
= Send five packets to the tap0 **interface**
time.sleep(1)
sendp([Ether(dst=ETHER_BROADCAST) / IP(src="1.2.3.4") / ICMP()], iface="tap0",
count=5)
= Wait for the threads
t_bridge.join()
t_sniff.join()
# Same tests, with "NAT" using xfrm function
= Run a sniff thread on the tap1 **interface**
t_sniff = Thread(
target=sniff,
kwargs={"iface": "tap1", "count": 5, "prn": Packet.summary,
"lfilter": lambda p: IP in p and p[IP].src == "2.3.4.5"}
)
t_sniff.start()
= Run a bridge_and_sniff thread between the taps **sockets**
def nat_1_2(pkt):
if IP in pkt and pkt[IP].src == "1.2.3.4":
pkt[IP].src = "2.3.4.5"
del pkt[IP].chksum
return pkt
return False
t_bridge = Thread(target=bridge_and_sniff, args=(tap0, tap1),
kwargs={"store": False, "count": 5, 'prn': Packet.summary,
"xfrm12": nat_1_2,
"lfilter": lambda p: IP in p and p[IP].src == "1.2.3.4"})
t_bridge.start()
= Send five packets to the tap0 **interface**
time.sleep(1)
sendp([Ether(dst=ETHER_BROADCAST) / IP(src="1.2.3.4") / ICMP()], iface="tap0",
count=5)
= Wait for the threads
t_bridge.join()
t_sniff.join()
= Delete the tap interfaces
tap0.close()
tap1.close()
tap0.delete()
tap1.delete()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment