source: ntrip/trunk/misc/ntripclient.pl@ 10502

Last change on this file since 10502 was 2486, checked in by stoecker, 15 years ago

added SSL test client

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#! /usr/bin/perl
2#
3# Name: ntripclient.pl
4# Authors: Dirk Stöcker
5# Description: perl script to access casters using HTTP and HTTPS
6
7use strict;
8#use warnings;
9#no warnings "uninitialized";
10use MIME::Base64;
11use Net::HTTP;
12use Net::HTTPS;
13use Net::SSLeay;
14use IO::Handle;
15STDOUT->autoflush(1);
16
17my $user = "...";
18my $pwd = "...";
19
20#getstream("ntrip.dgpsonline.eu", 80, "http", $user, $pwd, "WILD_RTK");
21#getstream("ntrip.dgpsonline.eu", 2101, "http", $user, $pwd, "WILD_RTK");
22getstream("ntrip.dgpsonline.eu", 443, "https", $user, $pwd, "WILD_RTK");
23
24sub printcert
25{
26 my $cert = $_[0];
27 return $cert;
28};
29
30sub getstream
31{
32 my ($server, $port, $protocol, $user, $pwd, $mp) = @_;
33 eval
34 {
35 local $SIG{ALRM} = sub { die "alarm"; };
36 alarm(20);
37 my $s;
38 if($protocol eq "https")
39 {
40 $s = Net::HTTPS->new(Host => "$server:$port", Timeout => 10);
41 if($s)
42 {
43 print "Cipher: ".$s->get_cipher()."\n";
44 my $cert = $s->get_peer_certificate();
45 print "Time: ".$cert->not_before() . " to " . $cert->not_after(). "\n";
46 print "Subject: ".printcert($cert->subject_name())."\n";
47 print "Issuer: ".printcert($cert->issuer_name())."\n";
48 print "\n";
49 }
50 }
51 else
52 {
53 $s = Net::HTTP->new(Host => "$server:$port", Timeout => 10);
54 }
55 if($s)
56 {
57 $s->write_request(GET => "/$mp", 'Host' => "$server:$port", Timeout => 10,
58 'User-Agent' => "NTRIP ssltestclient.pl/1.0",
59 "Ntrip-Version" => 'Ntrip/2.0',
60 ($user ? ("Authorization" => "Basic " . encode_base64("$user:$pwd")) : ())
61 );
62 my ($code, $message, %headers) = $s->read_response_headers;
63 print "$code $message\n";
64 foreach my $s (keys %headers)
65 {
66 print "$s: $headers{$s}\n";
67 }
68 print("\n");
69 if($code == 200)
70 {
71 while(1)
72 {
73 alarm(10);
74 my $n;
75 my $buf;
76 {
77 $n = $s->read_entity_body($buf, 1024);
78 }
79 last unless $n;
80 print $buf;
81 }
82 }
83 else
84 {
85 while(1)
86 {
87 my $buf;
88 my $n = $s->read_entity_body($buf, 1024);
89 last unless $n;
90 print $buf;
91 }
92 }
93 }
94 };
95}
Note: See TracBrowser for help on using the repository browser.