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 

LongIP QuadIP Convertor script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Dec 14, 2006 3:46 am    Post subject: LongIP QuadIP Convertor script Reply with quote

This script takes the longIP shown in eggdrop's dcc chat logs, for example, and converts them into their dotted quad IP, and can convert dotted quad IP into longIP.

I put this together with a bit of perl code translated to tcl, and some other snippets (I would still appreciate an answer to the question that I posted in the help forum about the inet_addr proc.. I'm using something different in this script for the time being.)

http://members.dandy.net/~fbn/longip.quadip.tcl.txt
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Thu Dec 14, 2006 12:51 pm    Post subject: A couple of suggestions... Reply with quote

- The regexp will match numbers that are outside the 0-255 range, so you should add some code verifying the numbers before converting the ip to decimal.
- Detecting if the decimal ip provided by a user is within the allowed range can not be done by a simple 'if' - use format %u (which will generate an error if the number is too large)
- Detecting if the input is a decimal or a dotted ip is easy, so you could merge the two public commands and have the script figure out what to do.
Here's some code (the irc part of it is not tested):
Code:
proc a2n dot {
   format %u [eval format 0x%02x%02x%02x%02x [split $dot .]]
}

proc n2a dec {
   join [scan [format %08x $dec] %2x%2x%2x%2x] .
}

proc longip ip {
   if {[string is digit -strict $ip]} {
      if {![catch {format %u $ip}]} {n2a $ip}
   } {
      if {![regexp {^([0-9]{1,3}\.){3}[0-9]{1,3}$} $ip]} {return ""}
      foreach o [split $ip .] {
         if {$o>255} {return ""}
      }
      a2n $ip
   }
}

bind pub - .longip [list irclongip 0]
bind msg - .longip [list irclongip 1]

proc irclongip {p n u h c {a ""}} {
   if {$p} {set a $c; set c $n}
   if {[set b [longip $a]]!=""} {
      puthelp "PRIVMSG $c :$a => $b"
   }
}

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Dec 15, 2006 12:36 pm    Post subject: Reply with quote

<stares in awe>

WOW! You're awesome Smile
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Dec 15, 2006 12:52 pm    Post subject: Reply with quote

OK, the awe is wearing off <grin> I tested the above, the msg bind doesn't work, not sure why since it's the same as the pub bind:

Tcl error [irclongip 1]: wrong # args: should be "irclongip p n u h c a"

I just made a small proc to handle the msg bind:
Code:

bind msg - .lip longipmsg
proc longipmsg {n u h a} {
        if {![onchan $n]} {return}
        irclongip 1 $n $u $h $a ""
        return
}
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Dec 15, 2006 1:00 pm    Post subject: Reply with quote

Oh wait, did you edit the example script, my first try did not have:

proc irclongip {p n u h c {a ""}} {

That works Smile

I had:
proc irclongip {p n u h c a} {

which didn't work for msg.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Dec 15, 2006 1:24 pm    Post subject: Reply with quote

I uploaded the fixed script to the url above. Also added checking whether user is either on channel or validuser for the msg bind.
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Mon Dec 18, 2006 7:34 am    Post subject: Reply with quote

I edited the script while you were testing I guess (the 'a' vs '{a ""}' thing) ... See comments in the code below:
Code:
proc longip ip {
   if {[string is digit -strict $ip]} {
   #edit: yes, it was a typo :)
      if {![catch {format %u $ip}]} {n2a $ip}
   } else {
      if {![regexp {^([0-9]{1,3}\.){3}[0-9]{1,3}$} $ip]} {return ""}
      foreach o [split $ip[set ip {}] .] {
         # format %g to avoid "invalid octal number" errors:
         set o [format %g $o]
         if {$o>255} {return ""} {lappend ip $o}
      }
      a2n [join $ip .]
   }
}

proc irclongip {p n u h c {a ""}} {
   if {$p} {
      if {[onchan $n]||[validuser $n]} {set a $c; set c $n} else {return}
   }
   # no need to trim both $a and $c
   set a [string trim $a]
   if {[set b [longip $a]]!=""} {
      puthelp "PRIVMSG $c :$a => $b"
   } else {
      puthelp "PRIVMSG $c :Invalid IP '$a' - IP must be a valid dotted quad IP or LongIP"
   }
}

_________________
Have you ever read "The Manual"?


Last edited by user on Mon Dec 18, 2006 5:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Mon Dec 18, 2006 4:12 pm    Post subject: Reply with quote

Is this a typo:
Code:

   if {[string is digit -strict $ip]} {
   } else {


The original used:
Code:

if {[string is digit -strict $ip]} {
     if {![catch {format %u $ip}]} {n2a $ip}
} else {
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Dec 18, 2006 5:39 pm    Post subject: Reply with quote

Obviously it's a typo, just remove the "} else {" line.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
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 -> Script Support & Releases 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