Advertisement
Guest User

ipinfo.tcl

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