ごく簡単な UPnP チェック

net/libnatpmp に /usr/local/bin/natpmpc が含まれていて、これを使えば簡単なチェックが出来るようだ。

成功する環境だと。
# pkg install libnatpnp
# natpmpc
initnatpmp() returned 0 (SUCCESS)
using gateway : 192.168.0.XXX
sendpublicaddressrequest returned 2 (SUCCESS)
readnatpmpresponseorretry returned 0 (OK)
Public IP address : XXX.XXX.XXX.XXX
epoch = 2744675207
closenatpmp() returned 0 (SUCCESS)
失敗する環境だと。
# natpmpc
initnatpmp() returned 0 (SUCCESS)
using gateway : 192.168.0.XXX
sendpublicaddressrequest returned 2 (SUCCESS)
readnatpmpresponseorretry returned -7 (FAILED)
readnatpmpresponseorretry() failed : the gateway does not support nat-pmp
  errno=61 'Connection refused'
-a オプションでポートマッピング要求の NAT-PMP も試せるっぽい。
# natpmpc -h
Usage :
  natpmpc [options]
        display the public IP address.
  natpmpc -h
        display this help screen.
  natpmpc [options] -a <public port> <private port> <protocol> [lifetime]
        add a port mapping.

Option available :
  -g ipv4address
        force the gateway to be used as destination for NAT-PMP commands.

  In order to remove a mapping, set it with a lifetime of 0 seconds.
  To remove all mappings for your machine, use 0 as private port and lifetime.

コメントする

perl adv
perl adv