Page 2 of 4

Find IP in text ?

Posted: Sun Oct 12, 2008 12:21 pm
by elfo116
My bot uses ftp lib for PB3.94. To rise estadicticas to a web
To create a function is complicated because the bot copies an item that the users announce. Example: 192.168.0.1 .. masters ... not roox version 1.0 go go etc :lol:

Posted: Sun Oct 12, 2008 12:55 pm
by Kaeru Gaman
To rise estadicticas to a web => to transfer/upload statistics to a website

you could program a string interpretation that extracts an IP...
should be not TO complicated.

Find IP in text ?

Posted: Sun Oct 12, 2008 12:59 pm
by elfo116
An example please.
Thanks.

Posted: Sun Oct 12, 2008 1:10 pm
by pdwyer
v4.20 has FTP built in, there would be minor code changes of course.

You still didn't explain why you can't use a DLL...

Find IP in text ?

Posted: Sun Oct 12, 2008 1:13 pm
by elfo116
Thanks to all, I am going to try the councils.

Posted: Sun Oct 12, 2008 2:17 pm
by Kaeru Gaman
XXX

Posted: Sun Oct 12, 2008 2:25 pm
by Kaeru Gaman
XXX

Posted: Sun Oct 12, 2008 2:32 pm
by AND51
Kaeru, your code is buggy:

Code: Select all

test$ = "the quick brown fox jumps over 15634 lazy dogs on 169.45.0. without any regrets! 169.45.0.1" 
Try it with this string.

@ pwdyer:
Why are you using 5 numbers per IP field in your regular expression?

Posted: Sun Oct 12, 2008 2:38 pm
by Kaeru Gaman
XXX

Posted: Sun Oct 12, 2008 2:53 pm
by pdwyer
AND51 wrote:@ pwdyer:
Why are you using 5 numbers per IP field in your regular expression?

Code: Select all

"([0-9][0-9][0-9]|[0-9][0-9]|[0-9]).([0-9][0-9][0-9]|[0-9][0-9]|[0-9]).([0-9][0-9][0-9]|[0-9][0-9]|[0-9]).([0-9][0-9][0-9]|[0-9][0-9]|[0-9])")

= 4 x "([0-9][0-9][0-9]|[0-9][0-9]|[0-9])."
    = [0-9][0-9][0-9] or [0-9][0-9] or [0-9]

As the number could be anything from 0.0.0.0 through 12.12.12.12 to 255.255.255.255

But if there is a bug, it would be that it would catch 999.999.999.999 as a valid IP address

Where does the "5" come from don't you mean 6 with the or'ing?

EDIT, there's probably a better way with conditionals like ([0-9]([0-9]([0-9]))). etc but I couldn't figure it out, this is the first time I've looked at the regular expression guide and tried to write one, the rest of the code is copied and pasted out of the PB CHM file :P

Posted: Sun Oct 12, 2008 2:58 pm
by AND51
@ pwdyer:
Sorry, I didn't recognize the vertical bar |.
What about the expression :)

Code: Select all

((1|2)?\d\d?\.){3}(1|2)?\d\d?
@ Kaeru Gaman:
Ah ok.
But if you would have read his posts carefully, you would know that his prefered format would be string.
His IRC bot needs to test, if a specified IP has got a running program on port 2300. So if the procedure returns a string, he can directly put it into OpenNetworkConnection().

Posted: Sun Oct 12, 2008 3:03 pm
by Kaeru Gaman
XXX

Posted: Sun Oct 12, 2008 3:24 pm
by pdwyer
AND51 wrote:@ pwdyer:
Sorry, I didn't recognize the vertical bar |.
What about the expression :)

Code: Select all

((1|2)?\d\d?\.){3}(1|2)?\d\d?
It's shorter, I don't understand it so I don't know if it works, does it run faster?

Edit, Sometime IP's are formated like this 139.023.198.123 (with a leading zero) and your expression fails here.

Posted: Sun Oct 12, 2008 3:27 pm
by Trond
Kaeru Gaman wrote:
But if you would have read his posts carefully, you would know that his prefered format would be string.
well, no.
I additionally had to have known anything about IRC-bots (what I don't do),
at least that he wants to use OpenNetworkConnection and that this function I don't know at all expects a string as argument.
see, smartass?
I didn't read the reason for this dispute, but the original poster clearly stated that he needs a string (just read his posts), and OpenNetworkConnection() definitely takes the ip address as a string as well (to support hostnames as well as ip addresses). That's why the first parameter reads ServerName$ with a $ at the end.

Have a nice day everyone. :)

Posted: Sun Oct 12, 2008 3:59 pm
by Kaeru Gaman
XXX