Save the following as act.py
and replace ACT_ACCOUNT_ID
with your ACT account ID and ACT_PASSWORD
with your ACT captive portal password (not your Wi-Fi router password unless they're the same).
Change ACT_SELFCARE_URL
to the correct captive portal link as well (use https://selfcare.actcorp.in/web/blr/home/-/act/
if you're unsure).
Install requests
with pip install requests
if you don't have it already.
Run the script with python act.py
-
Accept arguments from user and only perform the operation requested (e.g.
act login
oract logout
to login and logout respectively) -
Create INI/JSON file and store configuration in it and parse it at runtime (e.g.
ACT_ACCOUNT_ID
,ACT_PASSWORD
, etc.) -
If configuration is missing, ask user for it on first run and create the config file at runtime from user input
import requests, re, argparse
ACT_ACCOUNT_ID = "Enter ACT account ID here (e.g. 106003051395)"
ACT_PASSWORD = "Enter password for captive portal here (e.g. hunter2)"
ACT_SELFCARE_URL = "Enter your ACT selfcare captive portal URL here (e.g. https://selfcare.actcorp.in/web/blr/home/-/act/)"
ACT_NAT_IP = None # don't change this
# you may need to update this from time to time if the HTML changes
ACT_IP_REGEX = r"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"
# Input:
# {
# "loggedInUser": ACT_ACCOUNT_ID
# }
def logout(param_dict):
# (('loggedInUser', ACT_ACCOUNT_ID))
params = tuple(zip(list(param_dict), list(param_dict.values())))
response = None
try:
response = requests.get(f"{ACT_SELFCARE_URL}/logout", params=params)
except Exception as ex:
print(f"Exception occured while trying to GET {ACT_SELFCARE_URL}/logout:\r\n{ex}\r\n")
return None
return response
def find_act_ip():
response = None
try:
response = requests.get(ACT_SELFCARE_URL)
except Exception as ex:
print(f"Exception occured while trying to GET {ACT_SELFCARE_URL}:\r\n{ex}\r\n")
return None
matches = re.search(ACT_IP_REGEX, response.text)
if matches is not None:
return matches.group(1)
else:
print(f"Couldn't find a match for IP regex in {ACT_SELFCARE_URL}\r\n")
return None
pass
# Input:
# {
# "pword": ACT_PASSWORD,
# "_login_WAR_BeamPromotionalNDownloadsportlet_uname": ACT_ACCOUNT_ID
# }
def login(param_dict):
ACT_NAT_IP = find_act_ip()
if ACT_NAT_IP is None:
print("ACT_NAT_IP was not found. Can't login. Maybe Internet is down?\r\n")
return None
else:
# Add ACT_NAT_IP to POST data
param_dict['userIP'] = ACT_NAT_IP
try:
response = requests.post(f"{ACT_SELFCARE_URL}/login", data=param_dict)
except Exception as ex:
print(f"Exception occured while trying to POST to {ACT_SELFCARE_URL}/login:\r\n{ex}\r\n")
return None
return response
def check_response(operation='logout', response=None):
if response is None:
print(f"Exception occured while calling {operation.upper()} function!\r\n")
elif type(response) == str:
print(f"{operation.upper()} successful\r\nResponse: {response}\r\n")
elif response.status_code == 200:
print(f"{operation.upper()} successful\r\n")
else:
print(f"{operation.upper()} failed: {response.status_code}\r\n{response.text}\r\n")
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [OPERATION]",
description="Log in or log out of ACT Fibernet captive portal"
)
parser.add_argument("-li", "--login", action="store_true", help="Log in to ACT Fibernet captive portal")
parser.add_argument("-lo", "--logout", action="store_true", help="Log out of ACT Fibernet captive portal")
parser.add_argument("-i", "--ip", action="store_true", help="Print your IP as visible to ACT Fibernet captive portal")
return parser
def main():
parser = init_argparse()
args = parser.parse_args()
if any([args.login, args.logout, args.ip]):
# at least one arg was sent
if args.ip:
print(f"Trying to fetch your IP as seen by {ACT_SELFCARE_URL}\r\n")
response = find_act_ip()
check_response('find_act_ip', response)
if args.logout:
print(f"Trying to log out of and log back in to {ACT_SELFCARE_URL}\r\n")
response = logout({
'loggedInUser': ACT_ACCOUNT_ID
})
check_response('logout', response)
if args.login:
response = login({
'pword': ACT_PASSWORD,
'_login_WAR_BeamPromotionalNDownloadsportlet_uname': ACT_ACCOUNT_ID
})
check_response('login', response)
else:
# no args sent
parser.print_help()
return
if __name__ == "__main__":
main()
D:\Python>python act.py
usage: act.py [OPERATION]
Log in or log out of ACT Fibernet captive portal
optional arguments:
-h, --help show this help message and exit
-li, --login Log in to ACT Fibernet captive portal
-lo, --logout Log out of ACT Fibernet captive portal
-i, --ip Print your IP as visible to ACT Fibernet captive portal
D:\Python>python act.py --ip --logout --login
Trying to fetch your IP as seen by https://selfcare.actcorp.in/web/blr/home/-/act/
FIND_ACT_IP successful
Response: 1.2.3.4
Trying to log out of and log back in to https://selfcare.actcorp.in/web/blr/home/-/act/
LOGOUT successful
LOGIN successful