#!/usr/bin/env perl use strict; $|++; use Socket; use IO::Socket::INET; BEGIN { my $GATEWAY = "10.0.1.1"; my $sock = IO::Socket::INET->new(Proto => 'udp') or die; my $pmp = sockaddr_in(5351, inet_aton($GATEWAY)); sub chat { my $to_send = shift; send($sock, $to_send, 0, $pmp) or die "send: $!"; my $portaddr = recv($sock, my $incoming, 256, 0) or die "recv: $!" +; return sockaddr_in($portaddr), $incoming; } } { ## get external IP: my @r = chat(pack("C C", 0, 0)); my ($vers, $op, $result, $epoch, @ip) = unpack "C C n N C C C C", $r[2]; print "$vers $op $result $epoch @ip\n"; } my $PROTO = 2; # 1 = udp, 2 = tcp my $EXTERNAL = 8000; my $INTERNAL = 80; my $TIME = 3600; # seconds (max is 3600) while (1) { ## map external to internal my @r = chat(pack("C C n n n N", 0, $PROTO, 0, $INTERNAL, $EXTERNAL, + $TIME)); my ($vers, $op, $result, $epoch, $priv, $pub, $life) = unpack "C C n N n n N", $r[2]; print "$vers $op $result $epoch $priv $pub $life\n"; sleep $TIME / 2; # recommended }

In reply to Punch hole inbound for Apple NAT-PMP Router by merlyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.