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.

Regular expression matching hostname ips and vhosts

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Regular expression matching hostname ips and vhosts

Post by awyeah »

I use this to match 0.0.0.0 - 255.255.255.255

Code: Select all

regexp {([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})+$} [lindex [split $uhost @] 1]]
What would be the best way to match hostname ip's which aren't in their numerical format for instance: 376.bkj71.jaring.my or toronto-HSE-ppp3968878.sympatico.ca (so as to not differentiate them with vhosts)

I have come up with the logic? is this okay?? or can there be a better one

Code: Select all

regexp {([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,})+$} [lindex [split $uhost @] 1]]} {
Plus some as you see isp ips have 3 dots, 4 dots, some 5 dots (.'s) so how can we match those especially for these hostname ips?

And what about matching vhosts then? should only use [a-z] but how can we match vhosts they have many dots between words, some might have 1 if it is a domain or some more than 10 also. There are also numbers [0-9] present in vhosts?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Re: Regular expression matching hostname ips and vhosts

Post by De Kus »

awyeah wrote:I use this to match 0.0.0.0 - 255.255.255.255

Code: Select all

regexp {([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})+$} [lindex [split $uhost @] 1]]
What would be the best way to match hostname ip's which aren't in their numerical format for instance: 376.bkj71.jaring.my or toronto-HSE-ppp3968878.sympatico.ca (so as to not differentiate them with vhosts)

I have come up with the logic? is this okay?? or can there be a better one

Code: Select all

regexp {([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,})+$} [lindex [split $uhost @] 1]]} {
Plus some as you see isp ips have 3 dots, 4 dots, some 5 dots (.'s) so how can we match those especially for these hostname ips?

And what about matching vhosts then? should only use [a-z] but how can we match vhosts they have many dots between words, some might have 1 if it is a domain or some more than 10 also. There are also numbers [0-9] present in vhosts?
I don't believe you can find any IPs within an vhost without resolving it.
For ISP rdns hostnames, there might be a way to find most of them, but probably you have to do some |, because the format is so diffrent. Not too mention that some ISPs revers the IP order! So you will likely have to check against some known ISPs to filter it properly.

PS: Ah valid IP would rather match against: (stilll not error proof, but it will be rather complex to sort out everything ^^)
{([0-2]?[0-9]{1,2}).([0-2]?[0-9]{1,}).([0-2]?[0-9]{1,2}).([0-2]?[0-9]{1,2})+$}
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Sorry, for my regexp above, I pasted the wrong one. Anyway thanks De_Kus I will give your piece of code a try.

I came up with these, by looking at common ips throughout irc, but we would have to OR each of these, plus these aren't all the common ones there are more. Well yours looks smaller so I'll give it a go! ;)

Code: Select all

{([a-z][0-9]{1,}).([0-9]{2,}).([0-9]{2,}).([0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z][0-9]{1,}).([a-z]{2,3})+$}
{([a-z][0-9]{2,}).([a-z][0-9]{2,}).([0-9]{2,}).([0-9]{2,}).([0-9]{2,}).([a-z][0-9]{1,}).([a-z]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]{1,}).([a-z]{1,}).([a-z]]{1,}).([a-z]]{1,}).([a-z]]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]]{1,}).([a-z]]{1,}).([a-z]]{1,}).([a-z]]{2,3})+$}
{([0-9]{2,}).([a-z][0-9]{3,}).([a-z]{1,}).([a-z]{1,}).([a-z]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]{1,}).([a-z]{1,}).([a-z]{1,}).([a-z]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]{1,}).([a-z]]{1,}).([a-z]]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]{1,}).([a-z]{1,}).([a-z]{2,3})+$}
{([0-9]{2,}).([a-z][0-9]{3,}).([a-z]{1,}).([a-z]{2,3})+$}
{([a-z][0-9]{3,}).([a-z]]{1,}).([a-z]]{2,3})+$}
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

mine was just intented to be a replace for your {([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})+$} one ^-^. yours matchs up to 999, mine matchs up to 299, thats just the big deal :D.

that will consume some time.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

I had found another complex regexp function I will paste it later, I was unable to understand all of it detects from 0.0.0.0 to 255.255.255.255.

Also I needed to ask:

string match {[`_-^/{}]} $text

detects all these characters within the [ ]'s but if we put a [ or ] within them, it causes problems. I tried to escape them with a single \ or double ot triple backslash even but it doesn't work? How can this be achieved? if we want to detect [ and ] with string match.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

awyeah wrote:string match {[`_-^/{}]} $text

detects all these characters within the [ ]'s but if we put a [ or ] within them, it causes problems. I tried to escape them with a single \ or double ot triple backslash even but it doesn't work? How can this be achieved? if we want to detect [ and ] with string match.
the only thing i could succuessfully use in partyline was:
{[\133-\133\135-\135]}
without ranges it still gives the "you suck" return :D.
[14:46:11] tcl: evaluate (.tcl): string match {[\[\]]} "\["
Tcl: 0
[14:47:55] tcl: evaluate (.tcl): string match {[.[].]} "\["
Tcl: 0
[14:49:20] tcl: evaluate (.tcl): string match {[\133\135]} {[}
Tcl: 0
[14:49:29] tcl: evaluate (.tcl): string match {[\133-\135]} {[}
Tcl: 1
[14:49:54] tcl: evaluate (.tcl): string match {[\133-\133\135-\135]} {[}
Tcl: 1
strange thing, huh?
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

These are a bit complex, I found these for the 0.0.0.0 - 255.255.255.255
range err, but they don't seem to work, if I put a 256 in there it still gives me
'1' as the output in partyline, weird.

Code: Select all

(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
Any ideas guys?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

take a look at the testip proc in alltools.tcl
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Thanks gb your a life saver. ;)

I tried different combinations of these patterns, but seems as if regexp (in one pattern) can't handle situtations like this, or even if it can, I am unable to do it, heh. :D
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if you want to check exact you should consider storing the ip into 4 vars and check if 1 and 4 are between 0 and 255 (exclusive) and 2 and 3 between 0 and 255 (inclusive). Afaik the valid IPv4 range was 1.0.0.1 to 254.255.255.254.
I believe a few < and > checks on integer would be faster anyway than any extrem long regexp :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked