Files
assaultcube-/source/CubeMS/App_Code/IPTools.cs
T
driAn 8d65b707e6 masterserver
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1402 e016b1c5-ed68-44aa-a2f7-31cac88cffde
2007-10-27 18:22:20 +00:00

31 lines
826 B
C#

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
/// <summary>
/// Summary description for IPTools
/// </summary>
public static class IPTools
{
public static int IPToInt(IPAddress address)
{
byte[] ip = address.GetAddressBytes();
if(ip.Length == 4) return (int)(ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24));
else return 0;
}
public static IPAddress IntToIp(int address)
{
byte[] octets = { (byte)(address & 0xFF), (byte)((address >> 8) & 0xFF), (byte)((address >> 16) & 0xFF), (byte)((address >> 24) & 0xFF) };
return new IPAddress(octets);
}
}