Skip to content

Instantly share code, notes, and snippets.

@zpeters zpeters/whereami.tcl
Created Feb 27, 2017

Embed
What would you like to do?
#!/usr/bin/env tclsh
package require http
## Settings
set homeGateways {1.2.3.4 2.3.4.5}
### Procs
proc whereAmI {} {
global homeGateways
set tok [::http::geturl "http://httpbin.org/ip"]
set body [::http:::data $tok]
set ip [string trim [string map {"\"" ""} [lindex [split [lindex [split $body "\n"] 1] ":"] 1]]]
if {[lsearch $homeGateways $ip] >= 0} {
return "Home"
} else {
return "Remote"
}
}
### Main
puts [whereAmI]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.