Page 1 of 4

Find IP in text ?

Posted: Sun Oct 12, 2008 9:56 am
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.

Posted: Sun Oct 12, 2008 11:05 am
by Poshu
It can be done using regularexpression.

Posted: Sun Oct 12, 2008 11:18 am
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

Find IP in text ?

Posted: Sun Oct 12, 2008 11:26 am
by elfo116
Tanks u, but returned error; createregularexpresion() is not a function, an array, or linked list. I need a lib ?

Posted: Sun Oct 12, 2008 11:32 am
by pdwyer
using v4.2

Find IP in text ?

Posted: Sun Oct 12, 2008 11:35 am
by elfo116
I have very surce cod whit PB3.94 it is compatible this cods whit PB4.2 ?

Posted: Sun Oct 12, 2008 11:38 am
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.

Find IP in text ?

Posted: Sun Oct 12, 2008 11:41 am
by elfo116
Oh !, Thanks all :D

Posted: Sun Oct 12, 2008 11:46 am
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

Find IP in text ?

Posted: Sun Oct 12, 2008 11:52 am
by elfo116
Ah, and the user libs its compatible ?.

Posted: Sun Oct 12, 2008 11:54 am
by Kaeru Gaman
¡no!

most userlibs are not cross-version compatible.

Find IP in text ?

Posted: Sun Oct 12, 2008 11:58 am
by elfo116
Ohh!
This is a big big problem: (.
How can it use this function without updating my PB3.94?

Posted: Sun Oct 12, 2008 12:02 pm
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?

Find IP in text ?

Posted: Sun Oct 12, 2008 12:10 pm
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"

Posted: Sun Oct 12, 2008 12:15 pm
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