ip地址转换

 public String getIp(long ip10)
    {
        String ip = "";
        long temp = 0;
        for (int i = 3; i >= 0; i--)
        {
            temp = ip10 / (long)Math.Pow(256, i) % 256;
            if (i == 3)
            {
                ip = ip + temp;
            }
            else
            {
                ip = ip + "." + temp;
            }
        }
        return ip;
    }
    public static long getIp10(String ip)
    {
        long ip10 = 0;
        String[] ss = ip.Trim().Split('.');
        for (int i = 0; i < 4; i++)
        {
            ip10 +=(long) Math.Pow(256, 3 - i) * int.Parse(ss[i]);
        }
        return ip10;
    }

 

你可能感兴趣的:(IP地址)