Your IP : 216.73.216.247


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

import socket
import ssl

# EPP server configuration
HOST = 'epp.registry.net.za'
PORT = 700
USERNAME = 'enetworks'
PASSWORD = '36ancerg9a2'

# EPP XML templates
def epp_frame(xml):
    data = xml.encode('utf-8')
    length = len(data) + 4
    return length.to_bytes(4, byteorder='big') + data

login_xml = f"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <login>
      <clID>{USERNAME}</clID>
      <pw>{PASSWORD}</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>
        <svcExtension>
          <extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>
          <extURI>http://www.unitedtld.com/epp/charge-1.0</extURI>
          <extURI>http://co.za/epp/extensions/cozadomain-1-0</extURI>
          <extURI>http://co.za/epp/extensions/cozacontact-1-0</extURI>
        </svcExtension>
      </svcs>
    </login>
    <clTRID>ABC-12345</clTRID>
  </command>
</epp>"""
# Note: Replace xmlns below with the actual one from ZACR if different
balance_xml = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0"
         xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"
         xmlns:cozacontact="http://co.za/epp/extensions/cozacontact-1-0">
  <epp:command>
    <epp:info>
      <contact:info>
        <contact:id>enetworks</contact:id>
      </contact:info>
    </epp:info>
    <epp:extension>
      <cozacontact:info>
        <cozacontact:balance>true</cozacontact:balance>
      </cozacontact:info>
    </epp:extension>
    <epp:clTRID>ABC-BALANCE-0001</epp:clTRID>
  </epp:command>
</epp:epp>"""
# Helper to receive a full EPP response
def recv_epp_response(sock):
    # Read 4-byte header to get message length
    header = sock.recv(4)
    if len(header) < 4:
        raise Exception("Incomplete header received")
    length = int.from_bytes(header, byteorder='big')
    # Now read the full message (length - 4) bytes
    payload = b''
    while len(payload) < length - 4:
        chunk = sock.recv(length - 4 - len(payload))
        if not chunk:
            break
        payload += chunk
    return payload.decode('utf-8')

# Connect to EPP server
context = ssl.create_default_context()
with socket.create_connection((HOST, PORT)) as sock:
    with context.wrap_socket(sock, server_hostname=HOST) as ssock:
        # Receive greeting
        print("Greeting:\n", recv_epp_response(ssock))

        # Send login
        ssock.sendall(epp_frame(login_xml))
        print("Login Response:\n", recv_epp_response(ssock))

        # Send balance info request
        ssock.sendall(epp_frame(balance_xml))
        print("Balance Response:\n", recv_epp_response(ssock))