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 »

Some body can help me please ?
I need a procedure to find a IP in a text file and procedure return will be String.
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Post by Poshu »

It can be done using regularexpression.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Code: Select all

If CreateRegularExpression(0, "([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])")

  Dim Result$(0)
  
  a = ExtractRegularExpression(0, "here is some text with 139.123.123.123 and 1.23.2.223 as IP addresses", result$())
  
  MessageRequester("Info", "Nb strings found: "+Str(a))
  
  For k=0 To a-1
    MessageRequester("Info", Result$(k))
  Next

Else
  MessageRequester("Error", RegularExpressionError())
EndIf

Good excuse to learn how to use these :) Thanks. Probably a more efficient way though if you are good at writing these things
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 »

Tanks u, but returned error; createregularexpresion() is not a function, an array, or linked list. I need a lib ?
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

using v4.2
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 »

I have very surce cod whit PB3.94 it is compatible this cods whit PB4.2 ?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

3.94 code is partly compatible with 4.2, but 4.2 has a lot new functions, e.g. some for handling regular expressions.
if you need RegEx, you'll need 4.2

if you need 3.94 for completing some older project, download the 4.2 installer and put it in a new directory.
you can run two compiler versions on the same machine.
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 »

Oh !, Thanks all :D
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

some of the functions have a different number of parameters, like some of the windowID() or createdialog or allocatememory but they work the same. It could be a bit of work if you have lots of code but worth the effort since there was a lot of goodies in 4.0
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 »

Ah, and the user libs its compatible ?.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

¡no!

most userlibs are not cross-version compatible.
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 »

Ohh!
This is a big big problem: (.
How can it use this function without updating my PB3.94?
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Are there v4 versions of the libs? v4 has been out a while.

Can you install side by side and make a v4 compiled "IP Address search DLL" and use that in your current app and compile with 3.94?
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 »

Mmmm ...
no, i create a bot for Irc games and i need test if a ip is runing the game in the port 2300, i need a single exe .

"If it had known before this forum now he would be a better programmer"
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Looks like you're screwed then! :twisted:

...or you have to write your own function to do this. Find the "."s and check the distance between them, check if they are numbers then if so return it. Sounds like more effort that porting the code to the present version.

Are you sure the user libs won't work? not worth trying?

Why can't a bot use a DLL? I didn't understand your reason for that
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
Post Reply