MCPcopy Create free account
hub / github.com/secdev/scapy / tshark

Function tshark

scapy/sendrecv.py:1544–1567  ·  view source on GitHub ↗

Sniff packets and print them calling pkt.summary(). This tries to replicate what text-wireshark (tshark) would look like

(*args, **kargs)

Source from the content-addressed store, hash-verified

1542
1543@conf.commands.register
1544def tshark(*args, **kargs):
1545 # type: (Any, Any) -> None
1546 """Sniff packets and print them calling pkt.summary().
1547 This tries to replicate what text-wireshark (tshark) would look like"""
1548
1549 if 'iface' in kargs:
1550 iface = kargs.get('iface')
1551 elif 'opened_socket' in kargs:
1552 iface = cast(SuperSocket, kargs.get('opened_socket')).iface
1553 else:
1554 iface = conf.iface
1555 print("Capturing on '%s'" % iface)
1556
1557 # This should be a nonlocal variable, using a mutable object
1558 # for Python 2 compatibility
1559 i = [0]
1560
1561 def _cb(pkt):
1562 # type: (Packet) -> None
1563 print("%5d\t%s" % (i[0], pkt.summary()))
1564 i[0] += 1
1565
1566 sniff(prn=_cb, store=False, *args, **kargs)
1567 print("\n%d packet%s captured" % (i[0], 's' if i[0] > 1 else ''))

Callers

nothing calls this directly

Calls 2

sniffFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…