#!/usr/bin/perl # # getnonce # # Copyright (C) 2008 # Paul E. Jones # # This program will connect to Packetizer's nonce generation service and # return a unique nonce. # use LWP; # Service URL $url = "http://services.packetizer.com/nonce/?f=text"; # Define a user agent $ua = LWP::UserAgent->new; # Get the page from the server $response = $ua->get($url, "Accept" => "text/plain"); die "Error: Unable to get nonce: " . $response->status_line . "\n" unless $response->is_success; die "Error: Invalid content type: " . $response->content_type . "\n" unless $response->content_type eq "text/plain"; # Split the content into an array of lines @content_lines = split('\n', $response->content); # The first line contains the string "nonce=" if ($#content_lines >= 0) { ($tag, $nonce) = split('=', $content_lines[0]); if ($tag eq "nonce") { print "$nonce\n"; } else { die "Error: first line is not a nonce string\n"; } } else { die "Error: no data was returned by the server\n"; }