8000 parse_pcap_klap: require source host (#1137) · msz-coder/python-kasa@db80c38 · GitHub
[go: up one dir, main page]

Skip to content

Commit db80c38

Browse files
authored
parse_pcap_klap: require source host (python-kasa#1137)
Adds a mandatory `--source-host` to make sure the correct handshake is captured when multiple hosts are communicating with the target device.
1 parent 130e1b6 commit db80c38

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

devtools/parse_pcap_klap.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def main(
212212
username,
213213
password,
214214
device_ip,
215+
source_host,
215216
pcap_file_path,
216217
output_json_name=None,
217218
):
@@ -232,7 +233,6 @@ def main(
232233
)
233234

234235
operator = Operator(KlapTransportV2(config=fake_device), creds)
235-
236236
packets = []
237237

238238
# pyshark is a little weird in how it handles iteration,
@@ -241,6 +241,8 @@ def main(
241241
try:
242242
packet = capture.next()
243243
packet_number = capture._current_packet
244+
if packet.ip.src != source_host:
245+
continue
244246
# we only care about http packets
245247
if hasattr(
246248
packet, "http"
@@ -325,6 +327,11 @@ def main(
325327
required=True,
326328
help="the IP of the smart device as it appears in the pcap file.",
327329
)
330+
@click.option(
331+
"--source-host",
332+
required=True,
333+
help="the IP of the device communicating with the smart device.",
334+
)
328335
@click.option(
329336
"--username",
330337
required=True,
@@ -348,14 +355,14 @@ def main(
348355
required=False,
349356
help="The name of the output file, relative to the current directory.",
350357
)
351-
async def cli(username, password, host, pcap_file_path, output):
358+
async def cli(username, password, host, source_host, pcap_file_path, output):
352359
"""Export KLAP data in JSON format from a PCAP file."""
353360
# pyshark does not work within a running event loop and we don't want to
354361
# install click as well as asyncclick so run in a new thread.
355362
loop = asyncio.new_event_loop()
356363
thread = Thread(
357364
target=main,
358-
args=[loop, username, password, host, pcap_file_path, output],
365+
args=[loop, username, password, host, source_host, pcap_file_path, output],
359366
daemon=True,
360367
)
361368
thread.start()

0 commit comments

Comments
 (0)
0