做网络编程经常要把字符串型的ip地址转换为数值,有两种方法,第一种是任何语言都通用的,第二种是C#.net自有的方法:

我们以梦之都的IP为例:72.167.124.214

任何语言都通用的方法转换IP地址

a.b.c.d ==> a*256*256*256+b*256*256+c*256+d ===> 256*(c+256*(b+256*a))+d

示例:

72.167.124.214 ==> 72*256*256*256+167*256*256+124*256+214 ===> 256*(124+256*(167+256*72))+214

.net提供的方法转换IP地址

//字符串转换为数字
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse("72.167.124.214");
long dreamduip = ipaddress.Address;

//数字转换为字符串
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(dreamduip.ToString());
string strdreamduip = ipaddress.ToString();



http://www.youdao.com/smartresult-xml/search.s?type=ip&q=
http://fw.qq.com/ipaddress
 
 
转:http://www.dreamdu.com/blog/2009/08/04/ipaddress_tonumber/

相关文章:

  • 2022-12-23
  • 2022-01-19
  • 2021-12-13
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-07-31
  • 2022-12-23
  • 2021-12-22
  • 2022-01-28
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案