Skip to content

Commit

Permalink
fix: scapy fail in macos (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhdix authored Jun 10, 2022
1 parent b172730 commit 1ef37c8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions utils/dns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
from scapy.layers.dns import DNS, DNSQR
from scapy.layers.inet import IP, TCP, UDP
from scapy.all import DNS, DNSQR, IP, TCP, UDP

ACCESSIBLE_ADDRESS = "www.example.com"
DEFAULT_BLOCKED_ADDRESS = "www.twitter.com"
Expand Down
5 changes: 1 addition & 4 deletions utils/geolocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import platform
from urllib.request import Request, urlopen

from scapy.layers.dns import DNS, DNSQR, DNSRR
from scapy.layers.inet import IP, UDP
from scapy.sendrecv import sr
from scapy.volatile import RandShort
from scapy.all import DNS, DNSQR, DNSRR, IP, UDP, RandShort, sr

import utils.ephemeral_port

Expand Down
5 changes: 2 additions & 3 deletions utils/packet_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import json
import subprocess

from scapy.layers.inet import IP, TCP
from scapy.utils import hexdump, import_hexcap
from scapy.all import IP, TCP, hexdump, import_hexcap

FIREWALL_COMMANDS_HELP = "\r\n( · - · · · \r\n\
You may need to temporarily block RST output packets in your firewall.\r\n\
Expand Down Expand Up @@ -216,7 +215,7 @@ def from_json(cls, os_name: str, trace_retransmission: bool, packet_data: json):

@classmethod
def _read_interactive_packet(cls, show=False):
from scapy.layers.inet import IP, TCP
import scapy.all
banner = "Please create your packet in variable \"p\" and exit when you are done"
try:
from IPython.terminal.embed import InteractiveShellEmbed
Expand Down
17 changes: 8 additions & 9 deletions utils/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
from datetime import datetime
from time import sleep

from scapy.all import Raw, conf, get_if_addr
from scapy.layers.dns import DNS
from scapy.layers.inet import ICMP, IP, TCP, UDP
from scapy.sendrecv import send, sr, sr1
from scapy.volatile import RandInt, RandShort
from scapy.all import (DNS, ICMP, IP, TCP, UDP, RandInt, RandShort, Raw, conf,
get_if_addr, send, sr, sr1)

import utils.ephemeral_port
import utils.geolocate
Expand All @@ -23,7 +20,7 @@
LOCALHOST = '127.0.0.1'
SLEEP_TIME = 1
have_2_packet = False
user_iface=None
user_iface = None
measurement_data = [[], []]
OS_NAME = platform.system()

Expand Down Expand Up @@ -171,7 +168,8 @@ def send_packet_with_tcphandshake(this_request, timeout):
sport=source_port, dport=destination_port, seq=RandInt(),
flags="S", options=syn_tcp_options)
tcp_handshake_timeout = timeout + max_repeat
ans, unans = sr(send_syn, iface=user_iface, verbose=0, timeout=tcp_handshake_timeout)
ans, unans = sr(send_syn, iface=user_iface, verbose=0,
timeout=tcp_handshake_timeout)
if len(ans) == 0:
print("Warning: No response to SYN packet yet")
max_repeat += 1
Expand Down Expand Up @@ -454,7 +452,7 @@ def trace_route(
trace_with_retransmission: bool = False, iface=None
):
global user_iface
user_iface=iface
user_iface = iface
check_for_permission()
measurement_name = ""
request_packets = []
Expand Down Expand Up @@ -508,7 +506,8 @@ def trace_route(
paris_id = repeat_requests
elif trace_retransmission:
paris_id = -1
no_internet, public_ip, network_asn, network_name, country_code, city = utils.geolocate.get_meta(user_iface)
no_internet, public_ip, network_asn, network_name, country_code, city = utils.geolocate.get_meta(
user_iface)
if name_prefix != "":
measurement_name = name_prefix + '-' + network_asn + "-tracevis-" + \
datetime.utcnow().strftime("%Y%m%d-%H%M")
Expand Down

0 comments on commit 1ef37c8

Please sign in to comment.