This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

string is alpha ??

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

string is alpha ??

Post by Ofloo »

check ip for alpha

Code: Select all

set ip [lindex $arg 0]
if {[string is alpha $ip] == 1} {
  ...
}
if i enter ip like this 192.168.0.1 this would result non alpha string, 192.168.0.1a will result non alpha string 192.168.0a.1 same thing non alpha string 192.168a.0.1 same thing non alpha string

but if i move the a forward 192.168.a0.1 it will see the alpha

why is that 192.168.0.1q is non alpha string it contains apha chars ??
XplaiN but think of me as stupid
User avatar
BarkerJr
Op
Posts: 104
Joined: Sun Mar 30, 2003 1:25 am
Contact:

Post by BarkerJr »

Not really sure, but if you're trying to verify that it's an IP, I'd go with regexp. Something like:
if {[regexp ^\[0-9\]+\.\[0-9\]+\.\[0-9\]+\.\[0-9\]+$ $ip]} {
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

ok tnx this solves the alphas ;) but still got check if its lan ip or local host and so on ;) and if its a real ip of course hehe

but tnx its realy great syntax hehe
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

if you don't mind could you xplain what you did ? or ..?
XplaiN but think of me as stupid
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

So what, I got bored

Code: Select all

proc Ip2Int { ipDotAddr } {
    foreach ipByte [split $ipDotAddr {.}] {
        append hexAddr [format {%02x} $ipByte]
    }
    return [format {%u} "0x$hexAddr"]
}

proc IsPrivateIp {in} {
  if {![regexp ^\[0-9\]+\.\[0-9\]+\.\[0-9\]+\.\[0-9\]+$ $ip]} { error "Invalid IP input" }
  set ip [Ip2Int $in]
  if {($ip == 2130706433) || \
      (($ip >= 167772160) && ($ip <= 184549375)) || \
      (($ip >= 2886729728) && ($ip <= 2887778303)) || \
      (($ip >= 3232235520) && ($ip <= 3232301055))} {
    return 1
  } else { return 0 }
}
Use the "IsPrivateIp" function, and it will return 1 if it is a private / LAN IP, or 0 if public.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

damn! thats too hard to get :P
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

omg what the hell ! ? this looks great , do you get bored often :p when you do i know plenty stuff to do lmao just kidding tnx verry mutch ;)
XplaiN but think of me as stupid
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

It is actualy quite simple.

It is made up of two functions

Ip2Int

I have to confess, if you use that in a public script, you need to tag a header on
#######################################
# Source: iplib.tcl
# oreillynet.com
# Author: Michael Norton 04/19/2000
The original function (available HERE) was designed to convert a dotted IP address (xxx.xxx.xxx.xxx) into the HEX equivilant.

I hate bianry math, so I aint got a clue on conversion, however, I do know how to work from HEX.

I simply converted it to return a 32bit unsigned int of an IP address.

This is the same number used when sending your IP and port information in a DCC chat or send message to a client. Instead of the IP, it is a 32bit int representation.

The second proc is where the real checking is done.

First it checks if the input is a valid dotted IP, only made of digits.

It then converts the IP, using my first function.

Because IP addresses translate to 23bit numbers in sequence, you can easily check if the numbers are between certain ranges.

2130706433 is the representation of 127.0.0.1

167772160 is the representation of 10.0.0.0 and 184549375 is 10.255.255.255

So anything between the two numbers is a private IP. The other two sets of numbers relate to the other two private IP ranges.

It isn't actualy that hard, provided you understand a little bit about how IPs operate. I know hardly anything, however, what I did come accross allowed me to apply it here (I actualy learnt somthing from this).

As for doing small snippets. Try me!

I don't have the time to spend on anything over 30 lines line (lucky if I make it that far), however, smaller library/helper functions I love.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

lol Tnx for the script, ill keep it in mind ;)
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

you know unixtime write it looks funny with a date you could get a normal date but how do you see if something is like 1 or 2 or 3 days old from a unixtime .. ? like euhm if something is 3 days old .. if you time stamp something with unix time you could see if something is older then .. 2 3 or even 5 days or somehing like that it should be real small script but verry usefull and i don't understand the unixtime format, not need it write now .. but i will in near futur .. so if you could make stutch a script that be great hehe don't have to ofcourse
XplaiN but think of me as stupid
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

unixtime is the number of seconds since 00:00:00 01/01/1970. To find out if a timestamp is older than a given number of seconds, just add the number of seconds to the timestamp and compare it to the current time (or subtract them from the current time) :)
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm k ok i got it how can i is there a way i can set a unixtime to a user but so that it won't change ...? like an identifyer so i can call upon it when i need it or need to compare i know there is a last seen unixtime but is there a way to set second unixtime like that ?
XplaiN but think of me as stupid
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

setuser/getuser - check tcl-commands.doc for details (clue: XTRA)
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

k tnx found out how to work with it yep taken me a while hehe but now i know
XplaiN but think of me as stupid
Locked