Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remotely run a post script.......how to.....???

Status
Not open for further replies.

Goku81

Programmer
Mar 27, 2001
34
0
0
US
I work with network security at my company. there are devices on my network that have web access to change settings using forms. I wanna know how I would go about writing a Perl Script to activate the form post script on that web page for the device without even having to interact with a browser. Does anyone know how to go about doing this.
 
Have a look at this code sample:
Code:
use LWP::UserAgent;

$url  = '[URL unfurl="true"]http://bahn.hafas.de/bin/db.w97/query.exe/dn';[/URL]

@form = ('protocol'      => 'http:',	# Form content
         'from'          => 'augsburg hbf',
         'to'            => 'muenchen hbf',
         'via.1'         => '',
         'datesel'       => 'custom',
         'date'          => '24.03.98',
         'time'          => '24:00',
         'timesel'       => 'depart',
         'new_selection' => '',
         'start.x'       => '9',
         'start.y'       => '18');

$ua = LWP::UserAgent->new();					# Create User-Agent
$ua->proxy(['http', 'ftp'], "[URL unfurl="true"]http://yourproxy:8080");[/URL]

$request = HTTP::Request->new('POST', $url);	# Create Request
$request->proxy_authorization_basic('domain/user', 'password');

												# Declare form content
$request->content_type('application/x-[URL unfurl="true"]www-form-urlencoded');[/URL]

												# Create query string
while(($key, $value) = splice(@form, 0, 2)) {
    $value =~ s/[^\w-_]/sprintf "%%%02x", ord($&)/ge;
    $querystring .= "&" if $querystring;
    $querystring .= "$key=$value";
}
$request->content($querystring);
$response = $ua->request($request);
print $response->content();
You should remove the code for proxy access if you don't need it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top