egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unable to parse json, I need some help please

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
cnecrea
Voice


Joined: 08 Oct 2022
Posts: 3

PostPosted: Sat Nov 26, 2022 8:13 am    Post subject: Unable to parse json, I need some help please Reply with quote

Hi there,

I am unable to parse json from http://api.ipregistry.co

The json output is like:

Code:

{
"security": {
"is_abuser": false,
"is_attacker": false,
"is_bogon": false,
"is_cloud_provider": false,
"is_proxy": false,
"is_relay": false,
"is_tor": false,
"is_tor_exit": false,
"is_vpn": false,
"is_anonymous": false,
"is_threat": false
}
}


And this is a part of my TCL. Can some one help me with this, please? I'll appreciate a lot

Code:

# json parse
proc getjson {get data} {
   set parse [::json::json2dict $data]
   set return ""
   foreach {name info} $parse {
    if {[string equal -nocase $name $get]} {
      set return $info
      break;
      }
    }
    return $return
    }


# process check proxy
proc proxy_check {ip} {
global getjson
   set link "http://api.ipregistry.co/$ip?key=s1nr112dyxmw3oy9"
   set ipq [http::config -useragent "lynx"]
   set ipq [::http::geturl $link]
   set data [http::data $ipq]
    ::http::cleanup $ipq
    set is_abuser [getjson "is_abuser" $data]
    set is_attacker [getjson "is_attacker" $data]
    set is_bogon [getjson "is_bogon" $data]
    set is_cloud_provider [getjson "is_cloud_provider" $data]
    set is_proxy [getjson "is_proxy" $data]
    set is_relay [getjson "is_relay" $data]
    set is_tor [getjson "is_tor" $data]
    set is_tor_exit [getjson "is_tor_exit" $data]
    set is_vpn [getjson "is_vpn" $data]
    set is_anonymous [getjson "is_anonymous" $data]
    set is_threat [getjson "is_threat" $data]
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Sat Nov 26, 2022 1:53 pm    Post subject: Reply with quote

First, "global" is used for variables, not procedures.

And if you create a dict called parse, you must use the dict utilities:
Code:
proc getjson get data} {
   set parse [::json::json2dict $data]
   if {![dict exists $parse security $get]} {
      return ""
   } else {
      return [dict get $parse security $get]
   }
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber