Page 3 of 4

Posted: Sun Oct 12, 2008 4:14 pm
by AND51
Kaeru Gaman wrote:AND talked about OpenNetworkConnection...
how should I know it expects a string? I never used it.
Excuse me, I'm afk for a while => laughing :lol:

Of course, this topic is about the IP, not about network programming.
But you can just look at the manual, then you would have seen that I'm right.
And yes, in future, you should read each post twice, as I already said that OpenNetworkConnection() expects a string. And if the thread starter talks about his IRC bot and that he needs to connect to the IP returned by our procedure - it's clear that he needs a string.

Posted: Sun Oct 12, 2008 4:20 pm
by AND51
pdwyer wrote:Edit, Sometime IP's are formated like this 139.023.198.123 (with a leading zero) and your expression fails here.
Huh? I never saw an IP with leading zero.

IMHO this is not a valid IP. I just wrote "ping 127.000.000.001" into cmd.exe and it automatically turned the IP into "127.0.0.1".
So, in fact my expression is right.

But if you want to have this support, just use

Code: Select all

((0|1|2)?\d\d?\.){3}(|1|2)?\d\d?
And yes, my expression is faster, because I use the multiplicator. You just wrote [0-9] many times and used more |; the more OR-expressions, the slower the expression.

// Edit:
Your code is wrong, pwdyer!
You just use dot (.). But dot stands for every character, so you have to mask it!
Use \. (masked dot) instead, just like my procedure.

Posted: Sun Oct 12, 2008 4:22 pm
by Kaeru Gaman
XXX

Re: Find IP in text ?

Posted: Sun Oct 12, 2008 4:28 pm
by pdwyer
AND51, what are you on? :roll:

Just because you haven't seen the zero format it's doesn't exist? "Your humble opinion" on this counts for nothing! It exists, I've seen it, end of story. You will notice that with ping 127.000.000.001 it works though, ie its valid!

Yours is faster? okay, congrates, you're competing with someone who's never never used regular expressions before.

Thanks for the info about the dot, I didn't know that. offensively put but useful none the less

For your comments to KG, about reading the question twice... The posted question was
elfo116 wrote:Some body can help me please ?
I need a procedure to find a IP in a text file and procedure return will be String.
Is there some pedantic, childish competitive nature to you that you feel the needs to post in ways that are demeaning? Got self confidence issues do you and need to blow your own trumpet at others expense? :?

Posted: Sun Oct 12, 2008 4:31 pm
by DarkDragon
AND51 wrote:
pdwyer wrote:Edit, Sometime IP's are formated like this 139.023.198.123 (with a leading zero) and your expression fails here.
Huh? I never saw an IP with leading zero.
Just start your nintendo wii and configure it to have WLAN. It will generate leading zeros.

Posted: Sun Oct 12, 2008 4:39 pm
by Little John
Another approach. It also works when there is more than one IP address in the text (PB 4.20).

//edit: New improved code.
//edit: Fixed a bug.

Code: Select all

EnableExplicit

#IPchars = "0123456789."

Procedure.s IPAddress (text.s, begin=0)
   Static start
   Protected posn, i, v, ok, token.s, s.s

   If begin > 0
      start = begin
   EndIf

   While start <= Len(text)
      While start <= Len(text) And FindString(#IPchars, Mid(text, start, 1), 1) = 0
         start + 1
      Wend
      posn = start
      While posn <= Len(text) And FindString(#IPchars, Mid(text, posn, 1), 1) <> 0
         posn + 1
      Wend
   
      token = Mid(text, start, posn-start)
      start = posn
   
      If CountString(token, ".") = 3
         ok = #True
         For i = 1 To 4
            s = StringField(token, i, ".")
            If s = ""
               ok = #False
               Break
            EndIf
            v = Val(s)
            If v < 0 Or v > 255
               ok = #False
               Break
            EndIf
         Next
         If ok
            ProcedureReturn token
         EndIf
      EndIf
   Wend

   ProcedureReturn ""
EndProcedure


;-- Demo
Define text.s, address.s

text = "Some 15634 foxes jump over 169.45.0.2 lazy dogs on address 169.45.0. Another proper one is 3.145.5.72, while 169.45.0.2.2 is wrong."

address = IPAddress(text, 1)
While address
   Debug address
   address = IPAddress(text)
Wend
Regards, Little John

Posted: Sun Oct 12, 2008 4:40 pm
by AND51
> why do you always play the ...?
Well, I recommend you to remove this declaration. Otherwise, a mod will do that.

> "..." would be a compliment to you!
This, too of course.

> now it returns an IP found quite reliable
Well, I don't care about your code any longer. So, don't bother me with it, please.

> Just because you haven't seen the zero format it's doesn't exist?
Well, I have never seen this, so what? I read wikipedia, and there is not a single word about leading zeros in IPs.

> ping 127.000.000.001 it works though, ie its valid
This counts... nothing! This might is due the fact that ping.exe offers some kind of correction.
If you write "\\127.00.000.01" into the explorer, you will see that explorer.exe takes this IP without any correction.

> you're competing with someone who's never never used regular expressions before
Well, I saw your expression and I just wanted to help you. Are you lerning-resistent? Sorry, if I wanted to to you a favor.

> Just start your nintendo wii
Yes. I forgot that Nintendo is the creator of IPv4. Thanks.

Posted: Sun Oct 12, 2008 4:43 pm
by Trond
AND51 wrote: > now it returns an IP found quite reliable
Well, I don't care about your code any longer. So, don't bother me with it, please.
I thought you read this topic voluntarily? Or did you come here by a mixup of IPs? :o

Posted: Sun Oct 12, 2008 4:48 pm
by DarkDragon
AND51 wrote:> Just start your nintendo wii
Yes. I forgot that Nintendo is the creator of IPv4. Thanks.
No problem :-) . Such a big and wonderful company can't be wrong.
But IPv4 does not define if there's a leading zero or not. IPv4 just describes the binary side and that there are 4 numbers between 0 and 255 with a point in between and the netmasknotation is "ip/bits" or the bits written as ip.

Re: Find IP in text ?

Posted: Sun Oct 12, 2008 4:50 pm
by Kaeru Gaman
pdwyer wrote:For your comments to KG, about reading the question twice... The posted question was
elfo116 wrote:Some body can help me please ?
I need a procedure to find a IP in a text file and procedure return will be String.
Is there some pedantic, childish competitive nature to you that you feel the needs to post in ways that are demeaning? Got self confidence issues do you and need to blow your own trumpet at others expense? :?
I had to read the question twice because I misinterpreted it at first glance.
I said it was my fault, I know I read too quick sometimes...
some pun at the threadstarter was not intented and I'm sorry if it seemed so.

I just got a bit upset about the way of the other guy.
helping in finding some IP in the middle of some text has nothing to do with network programming.
I don't know anything about it, so I could not get the idea to look at OpenNetworkConnection.
but reading the whole network chapter of the manual was not a condition for helping with some string parsing problem.

Posted: Sun Oct 12, 2008 4:59 pm
by AND51
DarkDragon wrote:But IPv4 does not define if there's a leading zero or not.
Yes. After re-reading wikipedia, I understand this.
And I said it, that I didn't know this fact before!
But I also thank you for correcting me - that's why forums like this exist.

> I thought you read this topic voluntarily?
Indeed. First, I intended to participiate in here, but interests can change...

Posted: Sun Oct 12, 2008 5:38 pm
by Little John
AND51 wrote:that's why forums like this exist
But forums like this certainly have not been created for posting in ways that are demeaning, and for blowing one's own trumpet at others expense.

Regards, Little John

Posted: Sun Oct 12, 2008 8:00 pm
by AND51
Little John wrote:But forums like this certainly have not been created for...
...insulting other members, yes. That's why I say "case closed".

Just give me peace, so I can sleep well tonight — I suggest to delete all tainted posts (mine too, but not that with the RegExp).

Posted: Sun Oct 12, 2008 8:36 pm
by Psychophanta
Blah, blah blah, but nobody got a correct solution for this for PB ver 3.94 :roll:

Posted: Sun Oct 12, 2008 9:00 pm
by Little John
I don't think that I'm supposed to install PB 3.94, just because elfo116 is using it. It shouldn't be too hard to adapt Kaeru's or my code to PB 3.94.

Regards, Little John