Find IP in text ?

Just starting out? Need help? Post your questions and find answers here.
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Find IP in text ?

Post 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:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Find IP in text ?

Post by elfo116 »

An example please.
Thanks.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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...
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Find IP in text ?

Post by elfo116 »

Thanks to all, I am going to try the councils.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

XXX
Last edited by Kaeru Gaman on Mon Oct 13, 2008 6:57 pm, edited 1 time in total.
oh... and have a nice day.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

XXX
Last edited by Kaeru Gaman on Mon Oct 13, 2008 6:58 pm, edited 1 time in total.
oh... and have a nice day.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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?
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

XXX
Last edited by Kaeru Gaman on Mon Oct 13, 2008 6:58 pm, edited 1 time in total.
oh... and have a nice day.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Last edited by pdwyer on Sun Oct 12, 2008 2:59 pm, edited 1 time in total.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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().
Last edited by AND51 on Sun Oct 12, 2008 3:05 pm, edited 1 time in total.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

XXX
Last edited by Kaeru Gaman on Mon Oct 13, 2008 6:58 pm, edited 1 time in total.
oh... and have a nice day.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Last edited by pdwyer on Sun Oct 12, 2008 3:29 pm, edited 1 time in total.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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. :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

XXX
Last edited by Kaeru Gaman on Mon Oct 13, 2008 6:58 pm, edited 1 time in total.
oh... and have a nice day.
Post Reply