Last active
September 12, 2018 06:03
-
-
Save songzheng45/624785d36ab4f4d5b5d64a82fb993159 to your computer and use it in GitHub Desktop.
C# ip converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static long ToInt(string addr) | |
{ | |
// careful of sign extension: convert to uint first; | |
// unsigned NetworkToHostOrder ought to be provided. | |
return (long) (uint) IPAddress.NetworkToHostOrder( | |
(int) IPAddress.Parse(addr).Address); | |
} | |
static string ToAddr(long address) | |
{ | |
return IPAddress.Parse(address.ToString()).ToString(); | |
// This also works: | |
// return new IPAddress((uint) IPAddress.HostToNetworkOrder( | |
// (int) address)).ToString(); | |
} | |
static void Main() | |
{ | |
//假设www.sharejs.com服务器ip地址为:64.233.187.99,换后的结果为1089059683 | |
Console.WriteLine(ToInt("64.233.187.99")); | |
//1089059683转换后的结果为:64.233.187.99 | |
Console.WriteLine(ToAddr(1089059683)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IP转换工具: http://www.81874.com/tool/iptolong.php?ip=1.85.144.0&result=