import urllib.request, urllib.parse, http.cookiejar, re, sys, ssl

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj), urllib.request.HTTPSHandler(context=ctx))

dom = sys.argv[1] if len(sys.argv)>1 else "exnessvpn74efaadb"
mail = "test@example.com"
pw = "TestPass123"

# First hit main page to get session cookie
try:
    r = opener.open("https://www.duckdns.org/", timeout=15)
    html = r.read().decode('utf-8','ignore')
    print("MAIN PAGE status", r.status)
except Exception as e:
    print("main err", e); sys.exit(1)

# Find the add form action
m = re.search(r'<form[^>]*action="([^"]+)"[^>]*>', html)
print("form action:", m.group(1) if m else "NOT FOUND")
# find all input names in forms
for fm in re.finditer(r'<form[^>]*>(.*?)</form>', html, re.S):
    block = fm.group(0)
    inputs = re.findall(r'<input[^>]*name="([^"]+)"', block)
    action = re.search(r'action="([^"]+)"', block)
    if inputs:
        print("FORM action=", action.group(1) if action else None, "inputs=", inputs)
