IPs netmasks and subnets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vimadeva
Forum Newbie
Posts: 8
Joined: Tue May 01, 2007 3:51 pm

IPs netmasks and subnets

Post by vimadeva »

Hello!
This time my problem is that in my webpage I have to ask the user to introduce an ip and a subnetmask, and i need to get the proper subnet, and get validation for some ip ranges, like in a router I'll apreciate some help findding a function that allows me to do that. Thank you.
tikalacarnes
Forum Newbie
Posts: 7
Joined: Sat May 05, 2007 6:53 pm

Post by tikalacarnes »

are you using php, html or what and if it is php then this should work,

Code: Select all

if (isset($_SERVER)) 
	{
		if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) 
		{
			$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
		} 
		elseif (isset($_SERVER["HTTP_CLIENT_IP"])) 
		{
			$realip = $_SERVER["HTTP_CLIENT_IP"];
		} 
		else 
		{
			$realip = $_SERVER["REMOTE_ADDR"];
		}
	} 
	else 
	{
		if (getenv('HTTP_X_FORWARDED_FOR')) 
		{
			$realip = getenv('HTTP_X_FORWARDED_FOR');
		} 
		elseif (getenv('HTTP_CLIENT_IP')) 
		{
			$realip = getenv('HTTP_CLIENT_IP');
		} 
		else 
		{
			$realip = getenv('REMOTE_ADDR');
		}
	}
this will at least reveal the ip address of the user now the subnet mask i don't know. I use this code in my site to view who has been there with there ip address.
Post Reply