Your IP : 216.73.216.247


Current Path : /opt/cpanel/
Upload File :
Current File : //opt/cpanel/updatermns.py

#!/usr/bin/env python3
import socket
import ssl
import struct
import uuid

# ----- Config -----
EPP_HOST = "epp.zarc.net.za"
EPP_PORT = 700
EPP_USER = "enetworks"
EPP_PASS = "36ancerg9a2"

DOMAIN = "merqu.co.za"  # Replace with your actual domain

ADD_NS = [
    ("ns3.enetworks.co.za", "0.0.0.0"),      # Replace 0.0.0.0 with real IP if needed
    ("ns4.enetworks.net", "0.0.0.0")
]

REM_NS = [
    "ns1.mtnbusiness.net",
    "ns2.mtnbusiness.net"
]

# ----- EPP Helpers -----
def frame(xml_string):
    xml_bytes = xml_string.encode("utf-8")
    return struct.pack("!I", len(xml_bytes) + 4) + xml_bytes

def read_response(sock):
    header = sock.recv(4)
    if not header:
        return None
    total_length = struct.unpack("!I", header)[0]
    data = b""
    while len(data) < total_length - 4:
        chunk = sock.recv(total_length - 4 - len(data))
        if not chunk:
            break
        data += chunk
    return data.decode("utf-8")

def build_login_xml():
    return f"""<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <login>
      <clID>{EPP_USER}</clID>
      <pw>{EPP_PASS}</pw>
      <options>
        <version>1.0</version>
        <lang>en</lang>
      </options>
      <svcs>
        <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
        <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
        <objURI>http://co.za/epp/extensions/cozadomain-1-0</objURI>
        <objURI>http://co.za/epp/extensions/cozacontact-1-0</objURI>
      </svcs>
    </login>
    <clTRID>{uuid.uuid4()}</clTRID>
  </command>
</epp>"""

def build_update_dns_xml(domain, add_ns, rem_ns):
    # Add block with hostAddr
    add_ns_xml = ""
    for ns, ip in add_ns:
        add_ns_xml += f"""
        <domain:hostAttr>
          <domain:hostName>{ns}</domain:hostName>
        </domain:hostAttr>"""

    # Remove block (no IP needed)
    rem_ns_xml = ""
    for ns in rem_ns:
        rem_ns_xml += f"""
        <domain:hostAttr>
          <domain:hostName>{ns}</domain:hostName>
        </domain:hostAttr>"""

    return f"""<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <update>
      <domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
        <domain:name>{domain}</domain:name>

        <domain:add>
          <domain:ns>{add_ns_xml}
          </domain:ns>
        </domain:add>

        <domain:rem>
          <domain:ns>{rem_ns_xml}
          </domain:ns>
        </domain:rem>

      </domain:update>
    </update>
    <clTRID>{uuid.uuid4()}</clTRID>
  </command>
</epp>"""

# ----- Main -----
def main():
    context = ssl.create_default_context()
    with socket.create_connection((EPP_HOST, EPP_PORT)) as tcp_sock:
        with context.wrap_socket(tcp_sock, server_hostname=EPP_HOST) as epp_sock:
            print("[+] Connected to ZARC via TLS")

            # Greeting
            greeting = read_response(epp_sock)
            print("[i] Greeting:\n", greeting)

            # Login
            print("[*] Logging in...")
            epp_sock.sendall(frame(build_login_xml()))
            login_response = read_response(epp_sock)
            print("[i] Login Response:\n", login_response)

            # Update DNS
            print(f"[*] Updating nameservers for {DOMAIN}")
            update_xml = build_update_dns_xml(DOMAIN, ADD_NS, REM_NS)
            print("[i] Sending Update XML:\n", update_xml)
            epp_sock.sendall(frame(update_xml))
            update_response = read_response(epp_sock)
            print("[+] Update Response:\n", update_response)

if __name__ == "__main__":
    main()