| 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 |
|
|---|
| 7 | use strict;
|
|---|
| 8 | #use warnings;
|
|---|
| 9 | #no warnings "uninitialized";
|
|---|
| 10 | use MIME::Base64;
|
|---|
| 11 | use Net::HTTP;
|
|---|
| 12 | use Net::HTTPS;
|
|---|
| 13 | use Net::SSLeay;
|
|---|
| 14 | use IO::Handle;
|
|---|
| 15 | STDOUT->autoflush(1);
|
|---|
| 16 |
|
|---|
| 17 | my $user = "...";
|
|---|
| 18 | my $pwd = "...";
|
|---|
| 19 |
|
|---|
| 20 | #getstream("ntrip.dgpsonline.eu", 80, "http", $user, $pwd, "WILD_RTK");
|
|---|
| 21 | #getstream("ntrip.dgpsonline.eu", 2101, "http", $user, $pwd, "WILD_RTK");
|
|---|
| 22 | getstream("ntrip.dgpsonline.eu", 443, "https", $user, $pwd, "WILD_RTK");
|
|---|
| 23 |
|
|---|
| 24 | sub printcert
|
|---|
| 25 | {
|
|---|
| 26 | my $cert = $_[0];
|
|---|
| 27 | return $cert;
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | sub 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 | }
|
|---|