sheepla / pingu

🐧ping command but with pingu
MIT License
2.07k stars 64 forks source link

コマンドにIPv6用のオプションの追加 #19

Closed HidemaruOwO closed 2 years ago

HidemaruOwO commented 2 years ago

概要

IPv6へのIPにpingする機会がありました。
pingu --helpでコマンドIPv6用のオプション等があるか確認したら存在しませんでした。

再現手順

1, オプションなしのpinguコマンドでIPv6に対応してるかと思ったので、下のコマンドを実行しました。

$ pingu <IPv6 address>
[ ERROR ] an error occurred when running ping: write udp [::]:0->[IPv6 address]:0: sendto: no route to host

希望する動作

pinguコマンドに-ipv6オプションをつけて、引数にIPv6のアドレスを入力するとping結果が表示される

$ pingu -ipv6 <IPc6 address>

どうやらIPv6に対応してないようなので対応お願いします。

実行環境

スクリーンショット 2022-07-02 1 25 06
sheepla commented 2 years ago

コメントありがとうございます👀

現時点(v0.0.3)でpinguは既にIPv6に対応はできているという認識でした。特にオプションを指定しなくてもIPv6のアドレスにpingできるはずです。

pinguが使用しているライブラリgo-ping/pingは既にIPv6をサポートしており、標準パッケージのnet.ResolveIPAddr()を使って自動でアドレスが解決されるはずです。

ping.go#L106: New()NewPinger()の初期化時に "ip"という文字列を指定。これは自動でIPv4/IPv6が選択されるという意味っぽいです。 ping.go#L324: net.ResolveIPAddr()でアドレスを解決。

具体的に、どのIPv6のアドレスを指定してエラーになってしまったか知りたいので、それを教えていただくか、もしくは適当なパブリックDNSサーバのIPv6アドレスを指定したときの結果を教えてほしいです。

参考: IPv6対応のパブリックDNSサーバの一覧

sheepla commented 2 years ago

環境

Arch Linux x86 5.18.7-zen1-1-zen

バージョン

$ pingu --version
pingu: v0.0.3-rev379c118

Google Public DNS: 2001:4860:4860::8888 で試行した結果

bin/pingu 2001:4860:4860::8888
PING 2001:4860:4860::8888 (2001:4860:4860::8888) type `Ctrl-C` to abort
 ...        .     ...   ..    ..     .........            seq=0 32bytes from 2001:4860:4860::8888: ttl=112 time=20.821806ms
 ...     ....          ..  ..      ... .....  .. ..       seq=1 32bytes from 2001:4860:4860::8888: ttl=112 time=16.942872ms
 ...    .......      ...         ... . ..... #######      seq=2 32bytes from 2001:4860:4860::8888: ttl=112 time=24.3364ms
.....  ........ .###############.....  ... ##########.  . seq=3 32bytes from 2001:4860:4860::8888: ttl=112 time=15.070635ms
 .... ........#####################.  ... ###########     seq=4 32bytes from 2001:4860:4860::8888: ttl=112 time=14.977373ms
      ....... ######################.... ############     seq=5 32bytes from 2001:4860:4860::8888: ttl=112 time=15.095098ms
.    .  .... ########################... ###########      seq=6 32bytes from 2001:4860:4860::8888: ttl=112 time=15.500729ms
   ..   ....#########################.. .###########      seq=7 32bytes from 2001:4860:4860::8888: ttl=112 time=14.796595ms
    .       #########################.   .##########      seq=8 32bytes from 2001:4860:4860::8888: ttl=112 time=17.134441ms
   ....     .########################.      ########      seq=9 32bytes from 2001:4860:4860::8888: ttl=112 time=14.906298ms
  .....      .  ####################.        #######.     seq=10 32bytes from 2001:4860:4860::8888: ttl=112 time=14.224035ms
......     .. . ################## . .      .#######      seq=11 32bytes from 2001:4860:4860::8888: ttl=112 time=15.218631ms
......       #####################  .      .#######       seq=12 32bytes from 2001:4860:4860::8888: ttl=112 time=15.401727ms
......   .###########################  ..  #######        seq=13 32bytes from 2001:4860:4860::8888: ttl=112 time=14.673982ms
...    . ########################################.        seq=14 32bytes from 2001:4860:4860::8888: ttl=112 time=22.14071ms
       ####################################### .          seq=15 32bytes from 2001:4860:4860::8888: ttl=112 time=14.912607ms
      ##################################    .             seq=16 32bytes from 2001:4860:4860::8888: ttl=112 time=14.919792ms
     ###################################  ........        seq=17 32bytes from 2001:4860:4860::8888: ttl=112 time=15.434441ms
  .#####################################    .........     seq=18 32bytes from 2001:4860:4860::8888: ttl=112 time=21.095229ms
 .#######################################       .... . .  seq=19 32bytes from 2001:4860:4860::8888: ttl=112 time=14.630797ms

───────── 2001:4860:4860::8888 ping statistics ─────────
PACKET STATISTICS: 20 transmitted => 20 received (0% loss)
ROUND TRIP: min=14.224035ms avg=16.611713ms max=24.3364ms stddev=2.890968ms
sheepla commented 2 years ago

pinger.SetNetwork() を指定することで、IPv4またはIPv6のどちらか片方の使用を強制することができるので、pinguのinitPinger()関数の中身に以下を追記してビルド→実行するとIPv6のpingに成功するかもしれません。

func initPinger(host string, opts options) (*ping.Pinger, error) {
    // 略...
    pinger.SetNetwork("ip6")
    // 略...
}
HidemaruOwO commented 2 years ago

すみません。 pingu先のサーバーのファイアウォールがすべて拒否するようになってました.,,,,