Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have the source to a webpage, in the webpage contains information about what players are in our game server, as well as their IP's. I am making a tool to get this information and somehow extract it from this source then display it.

 

I'm not sure if 1 regular expression or a combination of them will work, i'm very new to Regex. So any help is appreciated. If Regex won't do, maybe some hints in the right direction toawrds parsing it out :)

 

Thanks guys

source.txt

-Sean
Posted

Question

 

I have the source to a webpage, in the webpage contains information about what players are in our game server, as well as their IP's. I am making a tool to get this information and somehow extract it from this source then display it.

 

I'm not sure if 1 regular expression or a combination of them will work, i'm very new to Regex. So any help is appreciated. If Regex won't do, maybe some hints in the right direction toawrds parsing it out :)

 

Thanks guys

 

In your text file I find (amongst others) the following two lines:

<tr><td>Web Key</td><td><input type=password name=webkey maxlength=32 size=35 value="F1414F141F1414F1414F1414F1414321"></td></tr>

<tr bgcolor=#808080><td><input type=submit value="Slot 01" name=1slot></td><td><font color=#FFFFFF>NullReference</font></td><td>69.139.11.62:2921</td><td>UPDT</td><td>0.0</td><td>1</td><td><tr bgcolor=#0000FF><td></td><td>1 Player</td><td></td><td></td><td></td><td></td><td></td></tr>

 

Do these two lines represent the ones with the IP and username?

 

Also, will the IP address always have a port (that is, ip colon port)?

 

Thanks. :)

Posted

I kinda figured it out the long drawn out way.

 

Yes richard, I want the playername, which then is followed by the IP and always has the port number.

 

I used a regex to split the font color which is exactly the save before every name, then i looped until i found the end of the font, did some subtraction and substringed the player name out.

 

To get the IP (I don't care about getting the port) i then used string.split to split the already split regex strings and got my IP that way. I didn't notice before how much repition there was that I could go by.

 

I much easier approach with a normal Regex string would be appreciated ;)

-Sean
Posted

This is one way

 

I kinda figured it out the long drawn out way.

 

Yes richard, I want the playername, which then is followed by the IP and always has the port number.

 

I used a regex to split the font color which is exactly the save before every name, then i looped until i found the end of the font, did some subtraction and substringed the player name out.

 

To get the IP (I don't care about getting the port) i then used string.split to split the already split regex strings and got my IP that way. I didn't notice before how much repition there was that I could go by.

 

I much easier approach with a normal Regex string would be appreciated ;)

 

 

Given the code from last post:

<tr><td>Web Key</td><td><input type=password name=webkey maxlength=32 size=35 value="F1414F141F1414F1414F1414F1414321"></td></tr>

<tr bgcolor=#808080><td><input type=submit value="Slot 01" name=1slot></td><td><font color=#FFFFFF>NullReference</font></td><td>69.139.11.62:2921</td><td>UPDT</td><td>0.0</td><td>1</td><td><tr bgcolor=#0000FF><td></td><td>1 Player</td><td></td><td></td><td></td><td></td><td></td></tr>

 

One thing you could do is use the following search strings:

 

name\=(.+)\s

 

The above search string will return the name ("webkey" in this case) as group 1, which is represented by the first, and only, set of parentheses. It says "find name followed by an equal sign followed by any characters followed by a white-space character".

 

[^0-9]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+):([0-9]+)[^0-9]

 

The above search string will return the ip address in group 1 and the port number in group 2, which are represented by the first and second group of parentheses. In the above code it would return "69.139.11.62" and "2921". It says "find a non-numeric character followed by 4 instances of (one or more numbers followed by a period) followed by a colon followed by one or more numbers followed by a non-numeric character".

 

Now...there are different ways to do this. If:

 

* your file has more than one user/ip entry and

* your file is broken into lines (delineated by newlines) and

* the pattern is always user then ip then user then ip...

 

Then:

 

You can just alternately call each of the above search strings and obtain each user and ip as you go. You will have to keep track of where you are in the data stream so that you don't start at the beginning each time and get the same search result over and over. I am guessing that the above starting point will get you going in the direction you need.

 

Just smack me for more or better info. :)

Posted

Richard,

 

The way you put it did the trick. My problem was I wasn't checking for a non-numeric character before the IP's. :o Sometimes I wonder if parts of my brain shut down.

 

Thank you very much!

-Sean

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...