怎么将int类型的数字转换成IP地址
如何将int类型的数字转换成IP地址
我运用了dll,成功连接后回调函数会自动返回一个int类型的IP号,现在我想把数字转换为IP地址,论坛上说要运用
IPAddress IP = new IPAddress(IP_Num);
lblIP.Text =IP.ToString();
其中IP_Num为返回的int类型IP号,但当我IP号为219.245.76.58时,返回的号码为-604681158,为负号。
我再使用上述方法时报错“指定的参数已超出有效值的范围”,请问这应该如何解决?
------解决方案--------------------
我运用了dll,成功连接后回调函数会自动返回一个int类型的IP号,现在我想把数字转换为IP地址,论坛上说要运用
IPAddress IP = new IPAddress(IP_Num);
lblIP.Text =IP.ToString();
其中IP_Num为返回的int类型IP号,但当我IP号为219.245.76.58时,返回的号码为-604681158,为负号。
我再使用上述方法时报错“指定的参数已超出有效值的范围”,请问这应该如何解决?
------解决方案--------------------
- C# code
protected void Page_Load(object sender, EventArgs e) { byte[] arr = BitConverter.GetBytes(-604681158); System.Text.StringBuilder item = new System.Text.StringBuilder(); for (int i = arr.Length-1; i >= 0; i--) { item.Append(arr[i].ToString() + "."); } Response.Write(item.ToString().Substring(0, item.ToString().Length - 1)); }