Index: README.md ================================================================== --- README.md +++ README.md @@ -34,11 +34,10 @@ - The Tcl package [dns](https://core.tcl.tk/tcllib/dir?ci=trunk&name=modules/dns&type=tree) - The Tcl package [defer](https://core.tcl.tk/tcllib/dir?ci=trunk&name=modules/defer&type=tree) - The Tcl package [lmdb](https://github.com/ray2501/tcl-lmdb) - The Tcl package [udp](http://tcludp.sourceforge.net/) - The Tcl package [tclreadline](http://tclreadline.sourceforge.net/) - - The curl command On a Debian system you should be able to do the following (to use the package): ``` $ sudo apt install -y tcl8.6 tcllib tcl-udp tcl-tclreadline curl Index: nano.tcl ================================================================== --- nano.tcl +++ nano.tcl @@ -1,9 +1,10 @@ #! /usr/bin/env tclsh package require Tcl 8.6.4 +package require http 2 package require json package require json::write namespace eval ::nano {} namespace eval ::nano::address {} @@ -2449,10 +2450,12 @@ proc ::nano::network::_localIP {version} { if {[info exists ::nano::network::_localIP($version)]} { return $::nano::network::_localIP($version) } + + package require http 2 ## XXX:TODO: Work out a better system for determining ones own IP switch -exact -- $version { v4 { set url "http://ipv4.rkeene.org/whatismyip" @@ -2460,16 +2463,35 @@ } v6 { set url "http://ipv6.rkeene.org/whatismyip" set localIPPrefix "" } + default { + return -code error "version must be \"v4\" or \"v6\"" + } } - set localIP [exec curl -sS $url] - if {$localIP eq ""} { - return -code error "Unable to lookup local IP $version" + catch { + set token [http::geturl $url -timeout 30000] + set ncode [http::ncode $token] + set data [http::data $token] + } error + + if {![info exists data]} { + set ncode -1 + set data $error } + + if {[info exists token]} { + http::cleanup $token + } + + if {$ncode ne "200"} { + return -code error "Unable to lookup local IP $version ($ncode: $data)" + } + + set localIP $data set localIP [string trim $localIP] set localIP "${localIPPrefix}${localIP}" set ::nano::network::_localIP($version) $localIP