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
265290ef
Commit
265290ef
authored
15 years ago
by
Dirk Loss
Browse files
Options
Downloads
Patches
Plain Diff
Added Windows-specific sniff() function
parent
13e894ef
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
scapy/arch/pcapdnet.py
+7
-1
7 additions, 1 deletion
scapy/arch/pcapdnet.py
scapy/arch/windows/__init__.py
+61
-0
61 additions, 0 deletions
scapy/arch/windows/__init__.py
with
68 additions
and
1 deletion
scapy/arch/pcapdnet.py
+
7
−
1
View file @
265290ef
...
...
@@ -10,9 +10,11 @@ from scapy.data import *
from
scapy.config
import
conf
from
scapy.utils
import
warning
from
scapy.supersocket
import
SuperSocket
from
scapy.error
import
Scapy_Exception
import
scapy.arch
if
conf
.
use_pcap
:
...
...
@@ -71,8 +73,10 @@ if conf.use_pcap:
def
__getattr__
(
self
,
attr
):
return
getattr
(
self
.
pcap
,
attr
)
open_pcap
=
lambda
*
args
,
**
kargs
:
_PcapWrapper_pcapy
(
*
args
,
**
kargs
)
class
PcapTimeoutElapsed
(
Scapy_Exception
):
pass
class
L2pcapListenSocket
(
SuperSocket
):
desc
=
"
read packets at layer 2 using libpcap
"
...
...
@@ -115,6 +119,8 @@ if conf.use_pcap:
pkt
=
self
.
ins
.
next
()
if
pkt
is
not
None
:
ts
,
pkt
=
pkt
if
scapy
.
arch
.
WINDOWS
and
pkt
is
None
:
raise
PcapTimeoutElapsed
try
:
pkt
=
cls
(
pkt
)
...
...
This diff is collapsed.
Click to expand it.
scapy/arch/windows/__init__.py
+
61
−
0
View file @
265290ef
...
...
@@ -453,6 +453,67 @@ def sndrcv(pks, pkt, timeout = 2, inter = 0, verbose=None, chainCC=0, retry=0, m
import
scapy.sendrecv
scapy
.
sendrecv
.
sndrcv
=
sndrcv
def
sniff
(
count
=
0
,
store
=
1
,
offline
=
None
,
prn
=
None
,
lfilter
=
None
,
L2socket
=
None
,
timeout
=
None
,
*
arg
,
**
karg
):
"""
Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets
count: number of packets to capture. 0 means infinity
store: wether to store sniffed packets or discard them
prn: function to apply to each packet. If something is returned,
it is displayed. Ex:
ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
if further action may be done
ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
"""
c
=
0
if
offline
is
None
:
if
L2socket
is
None
:
L2socket
=
conf
.
L2listen
s
=
L2socket
(
type
=
ETH_P_ALL
,
*
arg
,
**
karg
)
else
:
s
=
PcapReader
(
offline
)
lst
=
[]
if
timeout
is
not
None
:
stoptime
=
time
.
time
()
+
timeout
remain
=
None
while
1
:
try
:
if
timeout
is
not
None
:
remain
=
stoptime
-
time
.
time
()
if
remain
<=
0
:
break
try
:
p
=
s
.
recv
(
MTU
)
except
PcapTimeoutElapsed
:
continue
if
p
is
None
:
break
if
lfilter
and
not
lfilter
(
p
):
continue
if
store
:
lst
.
append
(
p
)
c
+=
1
if
prn
:
r
=
prn
(
p
)
if
r
is
not
None
:
print
>>
console
,
r
if
count
>
0
and
c
>=
count
:
break
except
KeyboardInterrupt
:
break
s
.
close
()
return
PacketList
(
lst
,
"
Sniffed
"
)
import
scapy.sendrecv
scapy
.
sendrecv
.
sniff
=
sniff
def
get_if_list
():
return
sorted
(
ifaces
.
keys
())
...
...
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