Sponsored Content
Top Forums Shell Programming and Scripting Can someone convert this python script to perl Post 303024717 by azdps on Monday 15th of October 2018 08:09:48 PM
Old 10-15-2018
Can someone convert this python script to perl

There is a python script that I would like converted to a perl script. If someone has the time to convert the script I would appreciate it. You can find the script below:

reboot-mb8600/reboot-mb8600.py at master . j4m3z0r/reboot-mb8600 . GitHub

Code:
#!/usr/bin/python

'''
A hacky script to reboot the Motorola MB8600 modem.
'''

import urllib, urllib2, sys
from bs4 import BeautifulSoup

MODEM_IP = '192.168.100.1'
USERNAME = 'admin'
PASSWORD = 'motorola'
ENCODED_PASSWORD = 'bW90b3JvbGE' # get from login URL from web UI.

def login(modem) :
    '''
    The modem seems to just be in a global "logged in" state once the password
    is sent -- no cookies are set.
    '''
    # the password is encoded with some simple function in JS. It is a
    # symmetric encoding of some form, so the encoding is always the same. This
    # is the encoding of the default password 'motorola'. Note that the ordering
    # of the arguments matters, and so does the trailing '=&' that we tack on
    # to the end of the URL.
    args = [
        ('loginUsername', USERNAME),
        ('loginPassword', ENCODED_PASSWORD)
    ]
    encodedArgs = urllib.urlencode(args)
    url = 'http://%(modem)s/login_auth.html?%(encodedArgs)s=&' % locals()

    # This will respond with a 200 return code with a HTML body claiming that
    # there was a 400 error if login was successful, or an actual 400 error if
    # the login was not successful.
    try :
        urllib2.urlopen(url).read()
    except urllib2.HTTPError, e :
        print >> sys.stderr, "400 error returned from modem. Check the password"
        raise e

def getSession(modem) :
    # the session key is included as a hidden field on the form with the reboot
    # button. We use BeautifulSoup to extract it.
    req = urllib2.Request('http://%(modem)s/MotoSecurity.html' % locals())
    html = urllib2.urlopen(req).read()
    soup = BeautifulSoup(html, "html.parser")
    sessionField = soup.find(attrs={'name' : 'sessionKey'})
    return str(sessionField.attrs['value'])

def reboot(modem, session) :
    # reconstruct the reboot request and send it here to start the reboot.
    argDict = [
        ('MotoUsername', USERNAME),
        ('MotoCurPassword', PASSWORD),
        ('MotoNewUsername', USERNAME),
        ('MotoNewPassword', PASSWORD),
        ('MotoRepPassword', PASSWORD),
        ('MotoSecurityAction', '1'),
        ('sessionKey', session)
    ]
    url = 'http://%(modem)s/goform/MotoSecurity' % locals()
    req = urllib2.Request(url, urllib.urlencode(argDict))
    urllib2.urlopen(req).read()

    # the response from the reboot request instructs us to visit this page, so
    # we do a fetch against it here. Otherwise the modem seems to not reboot.
    urllib2.urlopen('http://%(modem)s/rebootinfo.html' % locals()).read()

def main() :
    login(MODEM_IP)
    session = getSession(MODEM_IP)
    reboot(MODEM_IP, session)

if __name__ == '__main__' :
    main()

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert unix script to perl

Hi, I have these lines in a unix script: FILEONE = /<filepath1>/<filename1.txt> FILENEW = /<filepath2>/<filename2.txt> head -5 $FILEONE | sed '1d' > $FILENEW PARAM1 = `cat $FILENEW | awk '{print $2;}' ` echo "Param1 Value: $PARAM1" What's the correct syntax of the above lines if same... (2 Replies)
Discussion started by: gholdbhurg
2 Replies

2. Shell Programming and Scripting

Need to convert ksh script to Perl

Guys I am new to this forum, this may seem like a cheeky request. I have been asked by my manager to convert this ksh script to Perl. I do not have the foggiest about Perl and would appreciate any help on this. Basically this scipt automates a recovery process for EMC Legato Networker. It will... (1 Reply)
Discussion started by: rahimm1
1 Replies

3. Shell Programming and Scripting

Convert .sh script into perl

Good afternoon to you all I really need your help I have the following script developed in .sh and I need to convert it into perl. Can someone help me do it please? Here´s the script: ############################################## ############################################## ... (3 Replies)
Discussion started by: zarahel
3 Replies

4. Shell Programming and Scripting

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

5. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

6. Shell Programming and Scripting

Python/Perl script for auto login

I am loooking for a python/perl script which can login to gmail or any mail accounts and open a browser with the logged in page. I am trying this in a windows environment. I tried many docs available over internet an nothing seems to be working. (4 Replies)
Discussion started by: Tuxidow
4 Replies

7. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

8. Shell Programming and Scripting

Help with convert awk script into perl

Input file (a list of input file name with *.txt extension): campus.com_icmp_ping_alive.txt data_local_cd_httpd.txt data_local_cd.txt new_local_cd_mysql.txt new_local_cd_nagios_content.txt Desired output file: data local_cd_httpd data local_cd new local_cd_mysql new ... (9 Replies)
Discussion started by: perl_beginner
9 Replies

9. Shell Programming and Scripting

Convert shell script to Perl

Hello,,I have a very small script that contains these lines; and it works perfectly; however I need to use Perl now as I will need to feel variables from a MySQL table into this; to it would be nice to start by converting this first... find / -perm 777 \( -type f -o -type d \) -exec ls -lid {}... (1 Reply)
Discussion started by: gvolpini
1 Replies

10. Shell Programming and Scripting

Python script to convert date to iso format

Hi , This is my 1st program in python never tried any python before. i am trying to write a python script which reads a .tsv file line by line and in each line it should look for mm/dd/yyyy formate and convert it to yyyy-mm-dd formate . can some one provide be some sample code to do that. (2 Replies)
Discussion started by: vikatakavi
2 Replies
renpy(6)							       Games								  renpy(6)

NAME
renpy - engine for creating visual novels SYNOPSIS
renpy [path to the script directory] DESCRIPTION
Ren'Py is a programming language and runtime, intended to ease the creation of visual-novel type games. It contains features that make it easy to display thoughts, dialogue, and menus; to display images to the user; to write game logic; and to support the saving and loading of games. Ren'Py tries to be like an executable script, allowing you to get a working game without much more effort than is required to type the game script into the computer. Ren'Py is implemented on top of python, and that python heritage shows through in many places. Many Ren'Py statements allow python expres- sions to be used, and there are also Ren'Py statements that allow for the execution of arbitrary python code. Many of the less-used fea- tures of Ren'Py are exposed to the user by way of python. By only requiring use of the simplest features of python, it's hoped that Ren'Py will be usable by all game authors. USAGE
If you run the program without any arguments, zou will get an interactive launcher from where you can select, run and work different projects. For running a script, you need to give the full path to the directory that contains the game you want to play. For example: renpy /usr/share/games/renpy/demo/ To learn how to use the game interface, you should install and play renpy-demo. FILES
The game data for each user is stored at ~/.renpy/ directory. The scripts can be installed in the system bz placing them under /usr/share/games/renpy/ , but you can run any script in an arbitrarz directory just by telling the path as the parameter to the game. SEE ALSO
You can find more information at http://www.renpy.org/ May 2007 renpy(6)
All times are GMT -4. The time now is 04:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy