#!/usr/bin/perl
#######################
#
# Simple script to reliably reset Aastra phones
# Kurt Heston - 20061014
#
#######################
use strict;
use warnings;
use LWP;
my $browser = LWP::UserAgent->new;
#my $ip = "192.168.0.61";
my $ip = "$ARGV[0]";
$browser->cookie_jar({});
# Replace 'secret' with password
$browser->credentials(
"$ip:80",
'Please enter User name and password',
'admin' => 'secret'
);
my $url = "http://$ip/reset.html";
# Do a get so the phone can set a cookie
my $response = $browser->get( $url );
# Now send the reset command
$response = $browser->post( $url,
['resetOption' => '0']
);
die "$url error: ", $response->status_line
unless $response->is_success;
#print $response->content;
if( $response->content =~ m{Restarting the hardware} ) {
print "Phone at " . $ip . " restarted successfully\n";
} else {
print "Phone at " . $ip . " not restarted\n";
}
Shorter Examples
Using wget
wget --post-data=resetOption=0 --http-user=<username> --http-passwd=<password> http://ip.add.re.ss/reset.html^The Aastra 57i's tend to have a weird problem with sessions when using wget. It's ugly but precede the above wget statement with this line TWICE:
wget --no-cache --http-user=<username> --http-passwd=<password> http://ip.add.re.ss/logout.html
The reason for needing to issue this command twice is due to the buggy method Aastra uses to verify authentication. - Ransak
Using curl
Assuming IP is 192.168.10.20, username is "admin" and password is "2222":- requesting page directly causes an unauthorized error
- workaround is to request the javascript first.
- the 2nd request actually does the reset...
IN ASP.NET
foreach (var value in lis)
{
string URL = "http://" + value.IPaddress + "/reset.html";
Boolean ret = false;
string username = "admin";
string password = pwd;
var request = (HttpWebRequest)WebRequest.Create(URL);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Credentials = new NetworkCredential(username, password);
var responses = (HttpWebResponse)request.GetResponse();
// NameValueCollection formData = new NameValueCollection();
// formData["resetOption"] = "0";
//formData["t"] = "0";
//formData["a"] = "true";
// request.Headers.Add(formData);
if (responses.StatusCode == HttpStatusCode.OK)
{
ret = true;
}
using (WebClient wc = new WebClient())
{
wc.Headers.Add(HttpRequestHeader.Authorization, "Basic " +
Convert.ToBase64String(
Encoding.ASCII.GetBytes(username + ":" + password)));
NameValueCollection formDatas = new NameValueCollection();
formDatas["resetOption"] = "0";
formDatas["t"] = "0";
formDatas["a"] = "true";
formDatas.Add(formDatas);
byte[] responseBytes = wc.UploadValues(URL, "POST", formDatas);
string responsed = Encoding.ASCII.GetString(responseBytes);
}
}
0 Comments