Raised This Month: $ Target: $400
 0% 

Regex separating port from IP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
z3rongod
Member
Join Date: Jul 2009
Old 02-08-2010 , 10:57   Regex separating port from IP
Reply With Quote #1

Hello! I am trying to find a way to separate the port from IP using regex, but i have no clue how to achieve this. Wish there was a similar function as PHP's explode() :-)

new serverip[25]
new serverport[6]
get_user_ip(99, serverip, 25, 0)
...
z3rongod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-08-2010 , 11:02   Re: Regex separating port from IP
Reply With Quote #2

Using get_user_ip(), to get the ip without port, replace 0 by 1.

You can retrieve the "ip" as a server cvar the same for "port".

You don't need regex.

Edit : Or like said Yami, you can break using for example strtok().
__________________

Last edited by Arkshine; 02-08-2010 at 11:36.
Arkshine is offline
z3rongod
Member
Join Date: Jul 2009
Old 02-08-2010 , 11:28   Re: Regex separating port from IP
Reply With Quote #3

separate PORT from ip. I am trying to get the server's port and store it in a string.
z3rongod is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-08-2010 , 11:32   Re: Regex separating port from IP
Reply With Quote #4

Break the string at ':' and you will have the IP and Port.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
z3rongod
Member
Join Date: Jul 2009
Old 02-08-2010 , 11:48   Re: Regex separating port from IP
Reply With Quote #5

So there is a function similar to PHP's explode()

Could you please point it out for me?
z3rongod is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-08-2010 , 11:51   Re: Regex separating port from IP
Reply With Quote #6

Have you even looked for yourself yet?

http://amxmodx.org/funcwiki.php?go=func&id=872
http://amxmodx.org/funcwiki.php?go=func&id=860
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
z3rongod
Member
Join Date: Jul 2009
Old 02-08-2010 , 12:22   Re: Regex separating port from IP
Reply With Quote #7

Thank you
z3rongod is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-08-2010 , 12:48   Re: Regex separating port from IP
Reply With Quote #8

untested
PHP Code:
new szIPPort25 ];
new 
szPort];

get_user_ipid szIPPort charsmaxszIPPort ) );

new 
iPos strfindszIPPort ":" );

if ( 
iPos != -)
{
     
//Copy port to szPort string 
     
copyszPort charsmaxszPort ) , szIPPortPos ] );

     
//This will make szIPPort hold only the IP 
     
szIPPortiPos ] = EOS;

__________________

Last edited by Bugsy; 02-08-2010 at 12:53.
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-08-2010 , 13:18   Re: Regex separating port from IP
Reply With Quote #9

More easier to use strtok() :

PHP Code:
new ip  25 ]; 
new 
port]; 
    
get_user_ipid ip charsmaxip ) ); 
strtokipipcharsmaxip ), portcharsmaxport ), ':' ); 
__________________
Arkshine is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-08-2010 , 13:59   Re: Regex separating port from IP
Reply With Quote #10

IP addresses are only 15 characters Arkshine.

PHP Code:
new ip[16]
new 
port[6]

get_user_ip(idip15)
strtok(ipip15port5':'
Calling charsmax() is wasteful as well. You already know the size.
Spunky is offline
Send a message via AIM to Spunky
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode