Repository navigation
ScanAutomation
This section provides an overview of automated IPv6 firewall testing using IPscan, wget, curl or Python.
Please ensure that you accept the TermsOfUse and are authorised to perform IPv6 port scans against the machine that you wish to test BEFORE attempting any of the steps outlined below. Please also ensure that you are not accessing web pages using an HTTP proxy. If in doubt then a web proxy can be disabled by following the command-line examples shown below.
This website publishes a PrivacyPolicy. Continued use of this website implies your consent to the storage of data outlined in the policy.
It is possible to request automatic scans using wget, curl or scripting language, but the URLs must be constructed as shown below. In each case you MUST:
- target the IPscan IPv6 host and IPv6 cgi-bin directory (www66.chappell-family.co.uk/cgi-bin6/)
- use a text-browser compatible cgi target (ipscantxt.cgi or ipscanfasttxt.cgi)
- include an includeexisting query term, setting it to either 1 (to include the default ports listed in TCP Ports) or -1 (to exclude the default ports)
- include all 4 customport terms (numbered 0 to 3), setting them equal to nothing if they are unused
- include the termsaccepted term, setting it to 1 to indicate your acceptance of the terms and conditions TermsOfUse
- ensure that there are no spaces in the query string, particularly if using cut'n'paste
- wrap the resulting URL in quotes to ensure that the ampersand characters are not mis-interpreted
Failure to follow all of the above rules will result in a failure to scan your host. I'd also suggest that you specify a desired output document in the wget or curl command-line - otherwise the filename will be based on the called URL and so will be somewhat convoluted!
If you include the default ports (includeexisting=1) then the scan will take approximately 30-150 seconds to complete - so please be patient!
If you're intending to test a windows PC, then you need to be careful which pre-compiled version of wget you have installed. Some of the available versions do not include IPv6 support. Other good solutions for PC users can be found within the Cygwin tool or Window's WSL.
Now for some concrete examples:
wget --no-proxy --output-document=ipv6.html "https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=1&customport0=&customport1=&customport2=&customport3=&termsaccepted=1"
--2012-01-28 14:28:03-- https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=1&customport0=&customport1=&customport2=&customport3=&termsaccepted=1
Resolving www66.chappell-family.co.uk... 2001:470:971f:99::6
Connecting to www66.chappell-family.co.uk|2001:470:971f:99::6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10147 (9.9K) [text/html]
Saving to: `ipv6.html'
100%[======================================>] 10,147 --.-K/s in 0s
2012-01-28 14:28:03 (165 MB/s) - `ipv6.html' saved [10147/10147]
wget --no-proxy --output-document=ipv6.html "https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=-1&customport0=8080&customport1=&customport2=&customport3=&termsaccepted=1"
--2012-01-28 14:37:21-- https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=-1&customport0=8080&customport1=&customport2=&customport3=&termsaccepted=1
Resolving www66.chappell-family.co.uk... 2001:470:971f:99::6
Connecting to www66.chappell-family.co.uk|2001:470:971f:99::6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7323 (7.2K) [text/html]
Saving to: `ipv6.html'
100%[======================================>] 7,323 --.-K/s in 0s
2012-01-28 14:37:21 (112 MB/s) - `ipv6.html' saved [7323/7323]
wget --no-proxy --output-document=ipv6.html "https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=1&customport0=8080&customport1=33452&customport2=65535&customport3=&termsaccepted=1"
--2012-01-28 14:39:53-- https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi?includeexisting=1&customport0=8080&customport1=33452&customport2=65535&customport3=&termsaccepted=1
Resolving www66.chappell-family.co.uk... 2001:470:971f:99::6
Connecting to www66.chappell-family.co.uk|2001:470:971f:99::6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10263 (10K) [text/html]
Saving to: `ipv6.html'
100%[======================================>] 10,263 --.-K/s in 0s
2012-01-28 14:39:54 (222 MB/s) - `ipv6.html' saved [10263/10263]
Note in all cases the mandatory inclusion of the customportN queries, even though they are unused in these examples, and the termsaccepted query, signalling your acceptance of the scanner's terms and conditions of use. Note also that later versions of curl include a --noproxy option that can be used (--noproxy '*') to bypass the use of HTTP proxies. Please include this option if it is applicable to your deployment.
curl -sS "https://www66.chappell-family.co.uk/cgi-bin6/ipscanfasttxt.cgi?includeexisting=1&customport0=&customport1=&customport2=&customport3=&termsaccepted=1"
or
curl -sS "https://www66.chappell-family.co.uk/cgi-bin6/ipscanfasttxt.cgi?includeexisting=1&customport0=&customport1=&customport2=&customport3=&termsaccepted=1" | awk -F'[<> ]' 'BEGIN{printf("\nPORT\tSTATE\n")};{for(i=4;i<=NF;i++){if (index($i,"OPEN")>0 && $(i-1)=="=" && $(i-3)=="Port") {printf("%s\t%s\n",$(i-2),$i)}}};'
Results:
PORT STATE
53 UDPOPEN
53 TCPOPEN
80 TCPOPEN
443 TCPOPEN
3128 TCPOPEN
or, to report all non-STEALTH responses:
curl -sS "https://www66.chappell-family.co.uk/cgi-bin6/ipscanfasttxt.cgi?includeexisting=1&customport0=&customport1=&customport2=&customport3=&termsaccepted=1" | awk -F'[<> ]' 'BEGIN{printf("\nPORT\tSTATE\n")};{for(i=4;i<=NF;i++){if (index($i,"STEALTH")==0 && $(i-1)=="=" && $(i-3)=="Port") {printf("%s\t%s\n",$(i-2),$i)}}};'
Results:
PORT STATE
53 UDPOPEN
521 FAILEDPOLICY
547 ADMPHBTD
20 NOROUTE
23 TCPRST
24 ADMPHBTD
37 ADDRUNREACH
43 PORTUNREACH
53 TCPOPEN
79 FAILEDPOLICY
80 TCPOPEN
111 REJECTROUTE
443 TCPOPEN
3128 TCPOPEN
Ubiquity Edgerouters include curl and consequently it is possible to initiate a portscan against the router itself. It may be possible to achieve something equivalent on other embedded devices that include curl or wget.
On the router:
sudo /usr/bin/curl -G 'https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi' --data-urlencode 'includeexisting=1' --data-urlencode 'customport0=' --data-urlencode 'customport1=' --data-urlencode 'customport2=' --data-urlencode 'customport3=' --data-urlencode 'termsaccepted=1' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Connection: keep-alive' 2>&1 >/tmp/ipv6.html
sudo scp /tmp/ipv6.html <user>@<host>:
sudo rm -f /tmp/ipv6.html
Exchange and for an applicable account and machine name to transfer the results file to.
sudo /usr/bin/curl -G 'https://www66.chappell-family.co.uk/cgi-bin6/ipscantxt.cgi' --data-urlencode 'includeexisting=1' --data-urlencode 'customport0=' --data-urlencode 'customport1=' --data-urlencode 'customport2=' --data-urlencode 'customport3=' --data-urlencode 'termsaccepted=1' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Connection: keep-alive' 2>&1 >/tmp/ipv6.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2844 100 2844 0 0 30 0 0:01:34 0:01:33 0:00:01 627
A Python script to initiate an IPscan firewall test and then parse and report the results.
#!/usr/bin/python3
import urllib.parse
import urllib.request
import re
# Point at the 'fast' text version of IPscan
url = "https://www66.chappell-family.co.uk/cgi-bin6/ipscanfasttxt.cgi"
# change the customportN values for custom testing
# e.g. "customport0": 8123,
payload = {
"includeexisting": 1,
"customport0": 8123,
"customport1": "",
"customport2": "",
"customport3": "",
"termsaccepted": 1,
}
# Convert the payload dict to percent-encoded string
encoded_params = urllib.parse.urlencode(payload)
# Create full URL
full_url = f"{url}?{encoded_params}"
req = urllib.request.Request(full_url, method="GET", headers={"User-Agent": "IPscanAutomation/1.0"})
# Send GET and capture body response
with urllib.request.urlopen(req, timeout=50) as resp:
body = resp.read().decode("utf-8")
# list of response statuses that we don't want to report
EXCLUDED_STATUSES = {"TCPSTEALTH", "UDPSTEALTH"}
# ----------------------------------------------------------------------------------------
# regex to handle ICMPv6 echo request reporting
icmp_pattern = (
r'<td\s+title="IPv6 ping">\s*(.*?)\s*</td>\s*'
r'<td[^>]*>\s*'
r"((?:INDIRECT-)?([A-Z0-9 ]+))\s*"
r"(?:\(from\s+([a-fA-F0-9:]+)\))?"
r"\s*</td>"
)
icmp_match = re.search(icmp_pattern, body)
icmp_result = None
if icmp_match:
desc, raw_status, base_status, responder = icmp_match.groups()
icmp_result = {
"proto": "ICMPv6",
"description": desc.rstrip(" :"),
"status": raw_status.strip(),
"base_status": base_status.strip(),
"responder": responder or "target",
}
# ----------------------------------------------------------------------------------------
# regex to capture protocol context and the corresponding <table> block
section_pattern = (
r"<p>Individual\s+(UDP|TCP)\s+port\s+scan\s+results:</p>\s*<table[^>]*>(.*?)</table>"
)
non_stealth_ports = []
# Table Cell Pattern Group Breakdown:
# Group 1: Service description (from title="...")
# Group 2: Base port number (e.g. "123")
# Group 3: Optional protocol test index (e.g. "1" from "[1]", or None)
# Group 4: Full status string (e.g. "INDIRECT-PUNRCH" or "OPEN")
# Group 5: Base status code without "INDIRECT-" (e.g. "PUNRCH")
# Group 6: Optional responding device IPv6 address (or None)
cell_pattern = (
r'<td\s+title="([^"]*)"[^>]*>\s*'
r"Port\s+(\d+)(?:\[(\d+)\])?\s*=\s*"
r"((?:INDIRECT-)?([A-Z0-9]+))"
r"(?:\s+\(from\s+([a-fA-F0-9:]+)\))?"
r"\s*</td>"
)
# ----------------------------------------------------------------------------------------
# parse the body text into its constituent parts
for protocol, table_body in re.findall(section_pattern, body, re.DOTALL):
for match in re.finditer(cell_pattern, table_body):
service, port_num, test_idx, raw_status, base_status, responder = (
match.groups()
)
if base_status not in EXCLUDED_STATUSES:
# Reconstruct label with test index when present
port_label = (
f"Port {port_num}[{test_idx}]"
if test_idx
else f"Port {port_num}"
)
non_stealth_ports.append(
{
"proto": protocol,
"port": port_label,
"base_port": port_num,
"test_index": test_idx,
"service": service,
"status": raw_status,
"responder": responder or "target",
}
)
# ----------------------------------------------------------------------------------------
# Print the summary
if icmp_result:
responder_info = (
f" (via {icmp_result['responder']})"
if icmp_result["responder"] != "target"
else ""
)
print(
f"[{icmp_result['proto']}]{'':<13} | {'Service: ECHO REQUEST':<37} | Status: {icmp_result['status']}{responder_info}"
)
for entry in non_stealth_ports:
test_info = (
f" [Test #{entry['test_index']}]" if entry["test_index"] else ""
)
responder_info = (
f" (via {entry['responder']})" if entry["responder"] != "target" else ""
)
print(
f"[{entry['proto']}] {entry['port']:<14} | "
f"Service: {entry['service']:<28} | "
f"Status: {entry['status']}{test_info}{responder_info}"
)
Example results
The script above produces the following example results.
./scanme.py
[ICMPv6] | Service: ECHO REQUEST | Status: ECHOREPLY
[UDP] Port 53 | Service: DNS | Status: UDPOPEN
[UDP] Port 521 | Service: RIPng | Status: FAILEDPOLICY
[UDP] Port 547 | Service: DHCPv6 | Status: ADMPHBTD
[TCP] Port 20 | Service: FTP-data | Status: NOROUTE
[TCP] Port 23 | Service: Telnet | Status: TCPRST
[TCP] Port 24 | Service: Private Mail system | Status: ADMPHBTD
[TCP] Port 37 | Service: Time | Status: ADDRUNREACH
[TCP] Port 43 | Service: WHOIS | Status: PORTUNREACH
[TCP] Port 53 | Service: DNS | Status: TCPOPEN
[TCP] Port 79 | Service: Finger | Status: FAILEDPOLICY
[TCP] Port 80 | Service: HTTP | Status: TCPOPEN
[TCP] Port 111 | Service: SUN-RPC | Status: REJECTROUTE
[TCP] Port 443 | Service: HTTPS | Status: TCPOPEN
[TCP] Port 3128 | Service: Active API, or Squid Proxy | Status: TCPOPEN
A couple of Gemini prompts extended the Python script above to store the results in JSON format. In addition this version is suitable for cron scheduling and provides a summary of changes between consecutive results.
An example cron job for calling the script regularly:
0 3 * * * /usr/bin/python3 /path/to/ipscan_json_monitor.py >> /var/log/ipscan/cron.log 2>&1
The Python script ipscan_json_monitor.py:
#!/usr/bin/python3
import urllib.parse
import urllib.request
import re
import os
import sys
import json
from datetime import datetime, timezone
# Configuration
CONFIG = {
"url": "https://www66.chappell-family.co.uk/cgi-bin6/ipscanfasttxt.cgi",
"payload": {
"includeexisting": 1,
"customport0": 8123,
"customport1": "",
"customport2": "",
"customport3": "",
"termsaccepted": 1,
},
"data_dir": "/var/log/ipscan",
"history_file": "latest_scan.json"
}
def fetch_scan():
encoded_params = urllib.parse.urlencode(CONFIG["payload"])
full_url = f"{CONFIG['url']}?{encoded_params}"
req = urllib.request.Request(full_url, method="GET", headers={"User-Agent": "IPscanAutomation/1.0"})
try:
with urllib.request.urlopen(req, timeout=60) as resp:
return resp.read().decode("utf-8")
except Exception as e:
print(f"[ERROR] Failed to execute scan: {e}", file=sys.stderr)
sys.exit(1)
def parse_html_to_structured_data(body):
"""Parses HTML into a rich structured dictionary containing ICMPv6 and port scan data."""
data = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"icmpv6": None,
"ports": {}
}
# Parse ICMPv6 Ping / Echo Reply Status
icmp_pattern = (
r'<td\s+title="IPv6 ping">\s*(.*?)\s*</td>\s*'
r'<td[^>]*>\s*'
r"((?:INDIRECT-)?([A-Z0-9 ]+))\s*"
r"(?:\(from\s+([a-fA-F0-9:]+)\))?"
r"\s*</td>"
)
icmp_match = re.search(icmp_pattern, body)
if icmp_match:
desc, raw_status, base_status, responder = icmp_match.groups()
data["icmpv6"] = {
"description": desc.rstrip(" :"),
"status": raw_status.strip(),
"base_status": base_status.strip(),
"responder": responder if responder else "target"
}
# Parse TCP and UDP Port Scan Results
section_pattern = r"<p>Individual\s+(UDP|TCP)\s+port\s+scan\s+results:</p>\s*<table[^>]*>(.*?)</table>"
cell_pattern = (
r'<td\s+title="([^"]*)"[^>]*>\s*'
r"Port\s+(\d+)(?:\[(\d+)\])?\s*=\s*"
r"((?:INDIRECT-)?([A-Z0-9]+))"
r"(?:\s+\(from\s+([a-fA-F0-9:]+)\))?"
r"\s*</td>"
)
for protocol, table_body in re.findall(section_pattern, body, re.DOTALL):
for match in re.finditer(cell_pattern, table_body):
service, port_num, test_idx, raw_status, base_status, responder = match.groups()
port_key = f"{protocol}:{port_num}[{test_idx}]" if test_idx else f"{protocol}:{port_num}"
data["ports"][port_key] = {
"protocol": protocol,
"port": int(port_num),
"test_index": int(test_idx) if test_idx else None,
"service": service,
"status": raw_status,
"base_status": base_status,
"responder": responder if responder else "target"
}
return data
def compare_scans(old_data, new_data):
changes_detected = False
print("\n--- Structured Scan Comparison Report ---")
# Compare ICMPv6 Echo Reply Status
old_icmp = old_data.get("icmpv6")
new_icmp = new_data.get("icmpv6")
if old_icmp != new_icmp:
changes_detected = True
old_status = old_icmp.get('status') if old_icmp else 'NONE'
new_status = new_icmp.get('status') if new_icmp else 'NONE'
print(f"[ICMPv6 Echo Reply CHANGE] Status: {old_status} -> {new_status}")
if new_icmp and new_icmp.get('responder') != "target":
print(f" Responder shifted to: {new_icmp['responder']}")
else:
status_str = new_icmp.get('status') if new_icmp else 'NONE'
print(f"[OK] ICMPv6 Echo Reply unchanged: {status_str}")
# Compare TCP & UDP Ports (Additions, Removals, State Changes)
old_ports = old_data.get("ports", {})
new_ports = new_data.get("ports", {})
old_keys = set(old_ports.keys())
new_keys = set(new_ports.keys())
added = new_keys - old_keys
removed = old_keys - new_keys
common = old_keys & new_keys
for key in sorted(added):
changes_detected = True
p = new_ports[key]
print(f"[ADDED] {key} ({p['service']}) -> Status: {p['status']}")
for key in sorted(removed):
changes_detected = True
p = old_ports[key]
print(f"[REMOVED] {key} ({p['service']}) was ({p['status']})")
for key in sorted(common):
old_p = old_ports[key]
new_p = new_ports[key]
if old_p["status"] != new_p["status"]:
changes_detected = True
print(f"[CHANGED] {key} ({new_p['service']}): {old_p['status']} -> {new_p['status']}")
if not changes_detected:
print("[OK] No differences detected in ICMPv6 or port states.")
else:
print("\n[ALERT] Discrepancies detected between current and baseline runs.")
def main():
os.makedirs(CONFIG["data_dir"], exist_ok=True)
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
current_json_path = os.path.join(CONFIG["data_dir"], f"scan_{timestamp}.json")
latest_path = os.path.join(CONFIG["data_dir"], CONFIG["history_file"])
print("Executing IPscan test against remote CGI endpoint...")
html_body = fetch_scan()
# Parse HTML response into normalized structured JSON object
structured_data = parse_html_to_structured_data(html_body)
# Save current JSON dataset
with open(current_json_path, "w") as f:
json.dump(structured_data, f, indent=4)
# Compare against previous baseline if present
if os.path.exists(latest_path):
try:
with open(latest_path, "r") as f:
previous_data = json.load(f)
compare_scans(previous_data, structured_data)
except json.JSONDecodeError:
print("[WARN] Previous JSON history file was malformed. Establishing new baseline.")
else:
print("[INFO] Initial JSON baseline established successfully.")
# Update latest symlink pointer
if os.path.islink(latest_path) or os.path.exists(latest_path):
os.remove(latest_path)
os.symlink(os.path.basename(current_json_path), latest_path)
print(f"Structured JSON output saved to {current_json_path}")
if __name__ == "__main__":
main()
Example outputs:
./ipscan_json_monitor
Executing IPscan test against remote CGI endpoint...
[INFO] Initial JSON baseline established successfully.
Structured JSON output saved to /var/log/ipscan/scan_20261008_182819.json
./ipscan_json_monitor
Executing IPscan test against remote CGI endpoint...
--- Structured Scan Comparison Report ---
[OK] ICMPv6 Echo Reply unchanged: REJECTROUTE
[OK] No differences detected in ICMPv6 or port states.
Structured JSON output saved to /var/log/ipscan/scan_20261008_183701.json
./ipscan_json_monitor
Executing IPscan test against remote CGI endpoint...
--- Structured Scan Comparison Report ---
[ICMPv6 Echo Reply CHANGE] Status: REJECTROUTE -> FAILEDPOLICY
[ALERT] Discrepancies detected between current and baseline runs.
Structured JSON output saved to /var/log/ipscan/scan_20261008_185154.json