test.py 861 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. """Public IP detection: DNS reflection + HTTPS fallback both return a valid IPv4."""
  3. import sys, re
  4. err = []
  5. from core.main import UFONet
  6. app = UFONet()
  7. try:
  8. app.start_ship_engine()
  9. except SystemExit:
  10. pass
  11. except Exception:
  12. pass
  13. ipre = re.compile(r'^\d+\.\d+\.\d+\.\d+$')
  14. ip_dns = app._public_ip_via_dns()
  15. ip_http = app._public_ip_via_http()
  16. print(f"DNS (OpenDNS reflection): {ip_dns}")
  17. print(f"HTTP (randomized service): {ip_http}")
  18. if ip_dns is not None and not ipre.match(ip_dns):
  19. err.append(f"DNS returned non-IPv4: {ip_dns!r}")
  20. if ip_http is not None and not ipre.match(ip_http):
  21. err.append(f"HTTP returned non-IPv4: {ip_http!r}")
  22. if ip_dns is None and ip_http is None:
  23. err.append("Both DNS and HTTP IP lookups failed (no network?)")
  24. for e in err:
  25. print("FAIL:", e)
  26. sys.exit(0 if not err else 1)