Beruflich Dokumente
Kultur Dokumente
https://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
2) Download setuptools-0.6c11.win32-py2.7.exe(SetupTools)
https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-
py2.7.exe#md5=57e1e64f6b7c7f1d2eddfc9746bbaf20
3) Download NSSM from the link below which can be used to convert a batch file into a Windows
startup service.
http://nssm.cc/ci/nssm-2.24-23-gfb96938.zip
2.0Install Python
Install python-2.7.3.msi to C:\Python27
Now after installation the path needs to be added to Windows PATH variable Control Panel
>System>Advanced system settings
Go to Environment Variables >Path
Now copy setuptools-0.6c11.win32-py2.7.exe to C:\Python27 and then right click and run it as Admin
4.0Install Mechanize
Run an elevated command prompt (i.e. search>cmd>Right Click to run as Admin)
Write “pushd C:\Python27\Scripts” to move to the directory where you installed setuptools
#!/usr/bin/env python
import sys
import mechanize
import time
from optparse import OptionParser
import getpass
def Login(username,password):
print ">>> Trying to connect to login page.."
br = mechanize.Browser()
response = br.open('https://login.tikona.in')
print ">>> Opening Login Page Succeeded"
print ">>> " + br.title()
#print response.geturl()
#print ">>>"
print ">>> Redirecting to login.do"
br.select_form(nr=0)
br.form.action = 'https://login.tikona.in/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F&act=null'
br.form.method = 'POST'
print ">>> Submitting Username And Password.."
response = br.submit()
print ">>> Got Response For Credentials Entry"
br.select_form(name="form1")
br["username"] = username
br["password"] = password
br.find_control(name="type").value = ["2"]
br.form.method="POST"
print ">>> Proceeding to login.."
br.form.action="https://login.tikona.in/userportal/newlogin.do?phone=0"
print ">>> Logging in..."
print ">>> Login ok "
print ">>> " + br.title()
response = br.submit()
#response.get_data()
print ""
print 50 * "*"
print ""
print response.info()
print 50 * "*"
print ""
#print response.read()
def Logout():
print "Logging out.."
br = mechanize.Browser()
response = br.open('https://login.tikona.in/userportal/logout.do?svccat=1')
print response.geturl()
print response.info()
print response.read()
def main():
parser = OptionParser()
usage = "Usage: %prog -u <username>"
parser = OptionParser(usage=usage, version="%prog 1.0")
parser.add_option("-u", "--username", action="store", type="string",dest="user", help="Username to login")
(options, args) = parser.parse_args()
if options.user:
if __name__ == "__main__":
main()
This Tikona.py file will run the login to Tikona server.
Run this file in the following way from command prompt(-u parameter passes your User Id)
C:\Python27\Python.exeC:\Python27\Tikona.py -u1113214286
@echo off
cls
:START
ECHO.
ECHO ----Loop Start----
ECHO.
DATE /T
TIME /T
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Sent = 1, Received = 1" >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :GATEWAY
:GATEWAY
ECHO Failure in connecting to Google...
ECHO Checking Gateway 10.23.64.1, please wait...
@echo off
PING -n 1 10.23.64.1|find "Sent = 1, Received = 1" >NUL
IF NOT ERRORLEVEL 1 goto :GOOGLE
IF ERRORLEVEL 1 goto :CONNECTIVITY
:GOOGLE
ECHO Checking connection again since Gateway is Okay, please wait...
PING -n 1 www.google.com|find "Sent = 1, Received = 1" >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :LOGIN
:LOGIN
ECHO Gateway 10.23.64.1 is okay.....
ECHO Not Logged On To Tikona Broadband.....
ECHO Starting Tikona Login Python Script...
C:\Python27\python.exe C:\Python27\Tikona.py -u 1113214286
goto END
:CONNECTIVITY
ECHO The Gateway 10.23.64.1 is not yet active...
goto END
:SUCCESS
ECHO Internet connection is active...
::This makes the script wait for 5 mins if Internet is active
TIMEOUT /t 300 > NUL
goto END
:END
ECHO.
ECHO -----Loop End-----
ECHO.
goto START
7.0Automation Of the Batch Script
7.1 Option 1: (Run at machine start as a startup service)
If you want to run the script at machine startup i.e. without user logging in then follow these steps.
First we need to add the batch file to a Windows service(which runs at startup)
So we will download NSSM from the link below which can be used to convert a batch file into a Windows
startup service.
http://nssm.cc/ci/nssm-2.24-23-gfb96938.zip
Extract this folder and then get the nssm.exe(32 or 64 bit as per your OS from the folder win32 or win64)
In my case I used the nssm.exe from win64 folder.(On Windows 7/10 x64)
Now run a cmd window with Administrator privileges and enter nssm install Tikona
(Tikona is the service name that I used)
This brings up this window where we enter the Filename with Path.
Configure the service to run with the local Administrator account that you use (in my case it is AGENT47)
If you want the output to be written to a log file go to I/O tab and enter the log file name.
To keep the log file sizein check (max 1 MB or older than 1 day in my case) do the following.
Now you are done and click the Install service button .The script will now run when the machine is booted
(i.e. User logon is not needed)
7.2 Option 2: (Run at user logon as a Scheduled Task)
You can now double click this Login.bat file to run at login and now we will schedule this task via
Windows Task Scheduler.
Create a task
Enter the account password which you want to use to run this program
Now the task will run when the PC is booted up and you don’t have to worry about logging in manually
again.
There is an easier way to enable execution of the batch file at start in Windows 10.
Create a shortcut to Login.bat on the Desktop.
Now go to Run via WindowsKey+R and type shell:startup to open the startup folder.
This ensures that the batch file will be executed at machine startup but only after a user logs on.
7.4 Option 4: (Run at user logon as a Startup Script In Local Computer
Policy)
Run gpedit.msc
Local Computer Policy -> Computer Configuration -> Windows Settings -> Scripts (Startup/Shutdown)
Click add and then add file name along with path: C:\Python27\Login.bat