Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'''
from pywinauto.application import Application
app = Application(backend="uia").start("C:/Program Files (x86)/RSA SecurID Software Token/SecurID.exe")
keyboard.SendKeys('1')
print(list(app.Properties))
'''
import pyautogui as pygui
#import pywinauto
from pywinauto.application import Application
import pywinauto.keyboard as keyboard
import pyperclip
import os
rsa_passcode = '4321'
vpn_profile = "NJ - Data Center-RSA"
#"C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe"
# first get the token from rsa
app = Application().Start(cmd_line=u'"C:\\Program Files (x86)\\RSA SecurID Software Token\\SecurID.exe" ')
#app = Application().Start(cmd_line=u'"C:\\Program Files (x86)\\Notepad++\\notepad++.exe" ')
qwidget = app.QWidget
#print ("Here");
qwidget.Wait('ready')
qwidget.ClickInput()
for k in rsa_passcode:
print (k)
keyboard.SendKeys(k)
x, y = pygui.position()
# qwidget.MoveMouseInput(coords=(x + 80, y), pressed=u'', absolute=True)
qwidget.ClickInput(coords=(x + 80, y), absolute=True)
# pygui.click()
print (pygui.position())
# qwidget.MoveMouseInput(coords=(x + 60, y - 15), pressed=u'', absolute=True)
qwidget.ClickInput(coords=(x + 65, y + 40), absolute=True)
password = pyperclip.paste()
print (pygui.position())
#qwidget.close()
print (password)
print ('vpnclient connect "' + vpn_profile + '" pwd ' + password)
# os.system("cd ../../../Program Files (x86)/Cisco Systems/VPN Client")
os.chdir(r"C:\Program Files (x86)\Cisco Systems\VPN Client")
# os.system("pwd")
os.system('vpnclient connect "' + vpn_profile + '" pwd ' + password)
# now open vpn connect and paste in there
# app = Application().Start(cmd_line=u'"C:\\Program Files (x86)\\Cisco Systems\\VPN Client\\vpngui.exe" ')
# qwidget = app.QWidget
# pywinauto.timings.WaitUntilPasses(20, 0.5, lambda: pywinauto.findwindows.find_windows(title=u'status: Disconnected | VPN Client - Version 5.0.07.0290')[0])
# keyboard.SendKeys('{DOWN}')
# keyboard.SendKeys('{DOWN}')
# keyboard.SendKeys('^o')
# pywinauto.timings.WaitUntilPasses(20, 0.5, lambda: pywinauto.findwindows.find_windows(title=u'VPN Client | User Authentication for "NJ - Data Center-RSA"')[0])
# keyboard.SendKeys('^v')
# keyboard.SendKeys('{ENTER}')
# qwidget.Minimize()
'''
Access names : [u'QWidget', u'000154839210 - RSA SecurID Token', u'000154839210 - RSA SecurID TokenQWidget']
Class : QWidget
ClientRects : [<RECT L0, T0, R241, B147>]
ContextHelpID : 0
ControlCount : 0
ControlID : 0
ExStyle : 260
Fonts : [<LOGFONTW 'Segoe UI' -15>]
FriendlyClassName : QWidget
handle : 1443256
IsEnabled : True
IsUnicode : True
IsVisible : True
MenuItems : []
pwa_type : <class 'pywinauto.application.WindowSpecification'>
Rectangle : (L756, T132, R1015, B324)
Style : 382664704
Texts : [u'000154839210 - RSA SecurID Token']
UserData : 0
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment