Last active
November 20, 2023 18:12
-
-
Save aslafy-z/afa4023787a175724ee62da15ab38779 to your computer and use it in GitHub Desktop.
AutoKey script to relogin with Netskope client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Displays the information of the next window to be left-clicked | |
import time | |
import datetime | |
nsClientWindowName = "Netskope Client" | |
username = "" | |
password = "" | |
def window_wait_loose_focus(title, timeOut=0): | |
waited = 0 | |
while waited <= timeOut: | |
matched = False | |
wtitle = window.get_active_title() | |
matched = title == wtitle | |
if not matched: | |
return True | |
if timeOut == 0: | |
break # zero length timeout, if matched go straight to end | |
time.sleep(0.3) | |
waited += 0.3 | |
return False | |
def send_notification(content): | |
date = datetime.datetime.now().strftime('%Y-%m-%d %a') | |
system.exec_command("notify-send 'AutoKey' '"+date+"\n"+content.replace("'", "")+"\n'; echo") | |
def login(): | |
exists = window.wait_for_exist(nsClientWindowName, timeOut=10) | |
send_notification("window found: " + str(exists)) | |
if not exists: | |
return False | |
window.activate(nsClientWindowName, switchDesktop=False, matchClass=False) | |
send_notification("window focused") | |
time.sleep(10) | |
# Send credentials | |
keyboard.send_keys(username + "<tab>" + password + "<enter>") | |
send_notification("credentials stuffed") | |
closed = window_wait_loose_focus(nsClientWindowName, timeOut=30) | |
send_notification("window closed: " + str(closed)) | |
if not closed: | |
return False | |
return True | |
def check_login(): | |
exists = window.wait_for_exist(nsClientWindowName, timeOut=0) | |
if exists: | |
return False | |
output = system.exec_command("curl https://notskope.com", getOutput=True) | |
logged = output.count("You are using") == 1 | |
send_notification("check login: " + str(logged) + "\n" + str(output)) | |
return logged | |
while True: | |
username = system.exec_command("cat ~/username", getOutput=True).strip() | |
password = system.exec_command("cat ~/password", getOutput=True).strip() | |
if not check_login(): | |
login() | |
check_login() | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment