farrokhi / dnsdiag

DNS Measurement, Troubleshooting and Security Auditing Toolset
https://dnsdiag.org/
BSD 2-Clause "Simplified" License
942 stars 99 forks source link

Fail gently if cannot bind source port #96

Closed farrokhi closed 5 months ago

farrokhi commented 1 year ago

Currently we fail hard when we cannot bind to a source port (usually due to lack of permission). This might impact all the tools and need to be handled gracefully.

./dnsping.py -P784 -Q -c2 -s dns.adguard.com yahoo.com
WARNING: Source ports below 1024 are only available to superuser
dnsping.py DNS: 94.140.14.14:853, hostname: yahoo.com, proto: QUIC, rdatatype: A, flags: RD
Traceback (most recent call last):
  File "/Users/farrokhi/dev/dnsdiag/./dnsping.py", line 333, in <module>
    main()
  File "/Users/farrokhi/dev/dnsdiag/./dnsping.py", line 264, in main
    answers = dns.query.quic(query, dnsserver, timeout, dst_port,
  File "/Users/farrokhi/dev/dnsdiag/.venv/lib/python3.9/site-packages/dns/query.py", line 1123, in quic
    the_connection = the_manager.connect(where, port, source, source_port)
  File "/Users/farrokhi/dev/dnsdiag/.venv/lib/python3.9/site-packages/dns/quic/_sync.py", line 196, in connect
    (connection, start) = self._connect(address, port, source, source_port)
  File "/Users/farrokhi/dev/dnsdiag/.venv/lib/python3.9/site-packages/dns/quic/_common.py", line 165, in _connect
    connection = self._connection_factory(
  File "/Users/farrokhi/dev/dnsdiag/.venv/lib/python3.9/site-packages/dns/quic/_sync.py", line 88, in __init__
    self._socket.bind(
OSError: [Errno 22] Invalid argument