Page 1 of 1

IPs netmasks and subnets

Posted: Sat May 05, 2007 12:57 pm
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.

Posted: Sat May 05, 2007 7:44 pm
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.