Raised This Month: $ Target: $400
 0% 

Getting the first two octects of an IP address...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
P4rD0nM3
Veteran Member
Join Date: Feb 2006
Old 02-05-2009 , 11:38   Getting the first two octects of an IP address...
Reply With Quote #1

Hello, I was wondering how do you get the first two octets of an IP address?

Code:
    new clientIP[16];     get_user_ip(id, clientIP, 15, 1);

111.111.XXX.XXX

Does that mean I have to do get_user_up(id,clientIP,7,1)?

Last edited by P4rD0nM3; 02-05-2009 at 12:06.
P4rD0nM3 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-05-2009 , 12:30   Re: Getting the first two octects of an IP address...
Reply With Quote #2

If you want the 7 first characters, just do that :

new clientIP[8];
get_user_ip(id, clientIP, 7, 1);
Arkshine is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 02-05-2009 , 12:37   Re: Getting the first two octects of an IP address...
Reply With Quote #3

If you want both separated:

Code:
new ip[9], octet1[4], octet2[4]; get_user_ip(id, ip, 8, 1); // 111.111.XXX.XXX // ip now contains 111.111. strtok(ip, octet1, 3, ip, 7, '.'); strtok(ip, octet2, 3, ip, 7, '.'); // octet1 now contains 111 // octet2 now contains 111
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-05-2009 , 16:32   Re: Getting the first two octects of an IP address...
Reply With Quote #4

PHP Code:
new ip[9], newip[9];
get_user_ip(idip81); // 111.111.XXX.XXX
// ip now contains 111.111.

strtok(ipnewip3ip7'.');
add(newip8".");
strtok(ipnewip[3], 3ip7'.');
// newip contains 111.111 
Should work, not tested
__________________
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
P4rD0nM3
Veteran Member
Join Date: Feb 2006
Old 02-05-2009 , 16:24   Re: Getting the first two octects of an IP address...
Reply With Quote #5

Well I have this...

Code:
#include <amxmodx> new const cafeIP[][] = {     "192.168.",     "172.16.",     "10.16." }; public client_connect(id) {     new clientIP[8];     get_user_ip(id, clientIP, 7, 1);         for(new i = 0; i < sizeof(clientIP); i++)     {         if(containi(clientIP, clientIP[i]) != -1)         { // Give players automatic $16000 }     } }

And as you can see on the 10.16. if someone connects with 210.16, it returns true as well.

Since 10.16 is contained in 210.16.
P4rD0nM3 is offline
P4rD0nM3
Veteran Member
Join Date: Feb 2006
Old 02-05-2009 , 17:05   Re: Getting the first two octects of an IP address...
Reply With Quote #6

I didn't quite get it Yami sorry. I apologize.
P4rD0nM3 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-05-2009 , 17:06   Re: Getting the first two octects of an IP address...
Reply With Quote #7

newip will contain the first two octets only, no matter if it is 8.69 or 123.238
__________________
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
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-05-2009 , 17:11   Re: Getting the first two octects of an IP address...
Reply With Quote #8

Or what about:
Code:
new ip[9], octet1[4], octet2[4]; get_user_ip(client, ip, sizeof(ip) - 1, 1); replace_all(ip, sizeof(ip) - 1, ".", " "); strbreak(ip, octet1, sizeof(octet1) - 1, ip, sizeof(ip) - 1); strbreak(ip, octet2, sizeof(octet2) - 1, ip, sizeof(ip) - 1); // octet1 contains first number // octet2 contains second number
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
P4rD0nM3
Veteran Member
Join Date: Feb 2006
Old 02-05-2009 , 17:27   Re: Getting the first two octects of an IP address...
Reply With Quote #9

Ok let's say that 210.16 was client that connected.

But how do I make sure that when I compare

210.16 to 10.16 it wouldn't think that it's the same IP. Because that's what's happening.
P4rD0nM3 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-05-2009 , 17:43   Re: Getting the first two octects of an IP address...
Reply With Quote #10

Depending on which script you use,

Mine (you will have to remove the last '.' in the list of IPs or add another '.' to the end of newip):
PHP Code:
if (equal(newipcafeIP[i])) 
__________________
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
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 01:45.


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