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:
#!/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()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
LEARN ABOUT DEBIAN
ipcheck
IPCHECK(8) System Administration Utilities IPCHECK(8)NAME
ipcheck - dyndns.org client
DESCRIPTION
Usage : ipcheck.py [options] Username Password Hostnames or ipcheck.py [options] --acctfile acct_info_file
Options: -a address manually specify the address
-r URL NAT router, use web IP detection
-A text
scan syslog for an IP after text (Unix only)
-F filename
guess the WAN IP from a firewall log
-b backup mx option ON (default OFF)
-c custom dns option (default dynamic)
-d dir directory for data files (default current)
-e script
execute script after a successful update
-f force update regardless of current state
-g NAT router, let dyndns guess your IP (do not use this in a cronjob, try -r)
-h print this help text
--help print all available help text
-i interface
interface for local address (default ppp0)
-j disable https
-l log debugging text to ipcheck.log file
--syslog
log debugging text to syslog (Unix only)
-m mxhost
mx host (default NOCHG)
-o set dyndns offline mode
-p proxy bypass on port 8245
-q quiet mode (unless there is an error)
-s static dns option (default dynamic)
-t test run, do not send the update
-v verbose mode
-w wildcard mode ON (default OFF)
--makedat
create the ipcheck.dat file by dns lookup
--devices
print router options (Linksys, Netgear, etc)
-n ip the router IP address on the internal lan
For help with different options: python ipcheck.py -h For supported devices listing : python ipcheck.py --devices For long detailed help
text : python ipcheck.py --help
Make sure you can write to the current directory for data files and that you always run from the same directory. The first time you run
the script, you will be asked to run with the --makedat option in addition to any other options. This will create the data files for the
hostnames and options your specify on the command line. You should only do this once. Subsequent runs should be made without the --make-
dat option.
For help with different options: python ipcheck.py -h For supported devices listing : python ipcheck.py --devices For long detailed help
text : python ipcheck.py --help
Example 1: the external IP is on eth0 of the current machine python ipcheck.py -l -i eth0 username password hostnames
Example 2: you are using the Linksys routing device python ipcheck.py -l -L linksyspassword username password hostnames
Example 3: you want to use web based ip detection python ipcheck.py -l -r checkip.dyndns.org:8245 ...
where ... is your dyndns username password and hostnames. Hostnames should be comma delimited if there are more than one.
Debian GNU/Linux January 2012 IPCHECK(8)