Advertisement
s4turns

ipinfo.tcl

Jul 31st, 2019
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 0.77 KB | None | 0 0
  1. package require http
  2. package require json
  3.  
  4. bind pub - .who who
  5. proc who {nick uhost hand chan text} {
  6.    set lookup [lindex [split $text] 0]
  7.    catch {set http [::http::geturl http://ipinfo.io/$lookup/json -timeout 6000]} error
  8.    set data [::http::data $http]
  9.    set json [::json::json2dict $data]
  10.    ::http::cleanup $http
  11. set keys [dict keys $json]
  12. set expecting {ip hostname city region country loc postal phone org}
  13. foreach ele $expecting {
  14.    if {[lsearch $keys $ele] != -1} {
  15.       set $ele [dict get $json $ele]
  16.    } else {
  17.       set $ele "n/a"
  18.    }
  19. }
  20.    putserv "PRIVMSG $chan :\002(\002Geo\002)\002: IP: $ip - Hostname: $hostname - City: $city - Region: $region - Country: $country - Location: $loc - Zipcode: $postal - Organization: $org"
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement