Skip to content

Commit

Permalink
Use a list of DNS hosts instead of URLs for testing the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
d35ha committed Jan 28, 2025
1 parent 93ce8d3 commit cb0eefc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/fakenet-ng.vm/fakenet-ng.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>fakenet-ng.vm</id>
<version>3.3.0.20250117</version>
<version>3.3.0.20250128</version>
<description>FakeNet-NG is a dynamic network analysis tool.</description>
<authors>Mandiant</authors>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion packages/fakenet-ng.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ try {

# Replace `default.ini` with our modified one that includes change for 'internet_detector'.
# IMPORTANT: Keep our modified `default.ini` in-sync on updates to package.
$fakenetConfigDir = Get-ChildItem "C:\Tools\fakenet\*\configs"
$fakenetConfigDir = @(Get-ChildItem "C:\Tools\fakenet\*\configs")[0]
Copy-Item "$packageToolDir\default.ini" -Destination $fakenetConfigDir

# Create shortcut in Desktop to FakeNet tool directory
Expand Down
2 changes: 1 addition & 1 deletion packages/internet_detector.vm/internet_detector.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>internet_detector.vm</id>
<version>1.0.0.20241217</version>
<version>1.0.0.20250128</version>
<authors>Elliot Chernofsky and Ana Martinez Gomez</authors>
<description>Tool that changes the background and a taskbar icon if it detects internet connectivity</description>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion packages/internet_detector.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ New-Item -Path $toolDir -ItemType Directory -Force -ea 0
VM-Assert-Path $toolDir

# Install pyinstaller 6.11.1 (needed to build the Python executable with a version capable of executing in admin cmd) and tool dependencies ('pywin32')
$dependencies = "pyinstaller==6.11.1,pywin32"
$dependencies = "pyinstaller==6.11.1,pywin32==306,icmplib==3.0.4"
VM-Pip-Install $dependencies

# This wrapper is needed because PyInstaller emits an error when running as admin and this mitigates the issue.
Expand Down
24 changes: 11 additions & 13 deletions packages/internet_detector.vm/tools/internet_detector.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import winerror
import winreg

import threading
import requests
import urllib3
import icmplib
import signal
import ctypes
import time
Expand All @@ -30,12 +29,12 @@ import re

# Define constants
CHECK_INTERVAL = 2 # Seconds
CONNECT_TEST_URL_AND_RESPONSES = {
"https://www.msftconnecttest.com/connecttest.txt": "Microsoft Connect Test", # HTTPS Test #1
"http://www.google.com": "Google", # HTTP Test
"https://www.wikipedia.com": "Wikipedia", # HTTPS Test #2
"https://www.youtube.com": "YouTube", # HTTPS Test #3
}
TEST_IPS = [
"8.8.8.8", # Google
"8.8.4.4", # Google
"1.1.1.1", # Cloudflare
"1.0.0.1" # Cloudflare
]
SPI_SETDESKWALLPAPER = 20
SPIF_UPDATEINIFILE = 0x01
SPIF_SENDWININICHANGE = 0x02
Expand Down Expand Up @@ -306,12 +305,12 @@ def extract_title(data):
return None

def check_internet():
for url, expected_response in CONNECT_TEST_URL_AND_RESPONSES.items():
for ip_address in TEST_IPS:
try:
# Perform internet connectivity tests
response = requests.get(url, timeout=5, verify=False)
if expected_response in (extract_title(response.text) or response.text):
print(f"Internet connectivity detected via URL: {url}")
ip_host = icmplib.ping(ip_address, count=1, timeout=CHECK_INTERVAL)
if ip_host.is_alive:
print(f"Internet connectivity detected via IP: {ip_address}")
return True
except:
pass
Expand Down Expand Up @@ -468,7 +467,6 @@ def main_loop():

if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
default_transparency = get_transparency_effects()

# Try to load default settings from the registry
Expand Down

0 comments on commit cb0eefc

Please sign in to comment.