A script to authenticate to a Cisco Systems firewall needs to be converted from perl to Python.
This perl script needs to be converted to a python equivalent.
#!/usr/bin/perl
$login=$ARGV[0];
$pass=$ARGV[1];
# load necessary perl modules
use HTTP::Request::Common;
use LWP::UserAgent;
$url="https://<ip>/netaccess/loginuser.html";
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
# POST credentials
my $res = $ua->request(POST "$url", [username => "$login", password => "$pass", sid => "0"]);
$res->is_success or die "Failed to POST credentials to '$url': ", $res->status_line;
#!/bin/python
import requests
import urllib3
import sys
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
session = requests.Session()
payload = {'sid' : '0', "username" : sys.argv[1], "password" : sys.argv[2]}
r_post = session.post("https://<ip>/netaccess/loginuser.html",
data=payload,
verify=False,
)
print(r_post.text)
The result is actually not the same. I looks like python is sending this as a parameters in the URL, while with perl this is in the form.
UPDATE :
The page that I try to use is :
</style>
</head>
<body bgcolor=white alink="#333366" vlink="#333366" link="#333366">
<script language="JavaScript1.1">
function doRefresh()
{
location.replace("/netaccess/connstatus.html");
}
</script>
<FORM method=post ACTION="/netaccess/connstatus.html">
<INPUT type=hidden name=sid VALUE="0">
<h3>Network User Authentication</h3><p><p>Network User Authentication is <i>required</i>.</p> <table border cellpadding=5><tr><td><input type=submit width=120 style="width:120" name=login value="Log In Now"></td><td><b>You are not logged in.</b><br>User IP: <br></td></tr></table><script language="JavaScript">document.forms[0].login.focus()</script>
</FORM>
</body>
</html>