------解决方案-------------------- GetAddressBytes()
------解决方案-------------------- 是提取出来,用十六进制表示么?
------解决方案-------------------- ip地址本质就是4个byte
------解决方案--------------------
private void button2_Click(object sender, EventArgs e) { IPAddress test = IPAddress.Parse("127.0.0.1"); String[] result = new string[4]; result = test.ToString().Split('.'); string final = str2hex(result, 4); MessageBox.Show(final); } public String int2hex(uint src) { String result = ""; if (src < 10) { result = src.ToString(); } else { switch (src) { case 10: result = "A"; break; case 11: result = "B"; break; case 12: result = "C"; break; case 13: result = "D"; break; case 14: result = "E"; break; case 15: result = "F"; break; } } return result; } public string str2hex(string[] source, int num) { string temp; string result = ""; for (int str2hexcount = 0; str2hexcount < num; str2hexcount++) { String valuetemp = "0x"; temp = source[str2hexcount]; uint value = Convert.ToUInt32(temp); if (value > 255) { MessageBox.Show("超出范围"); } else { uint b = value / 16 % 16; valuetemp = valuetemp + int2hex(b); uint a = value % 16; valuetemp = valuetemp + int2hex(a) + ";"; source[str2hexcount] = valuetemp; }
} for (int i = 0; i < num; i++) { result = result + source[i]; } return result; }
------解决方案-------------------- 转换的是127.0.0.1,方法写在按钮事件那个函数里面,有两个子函数str2hex和int2hex
------解决方案-------------------- 对于每一个相应的uint,左移8位并且与下一个数字|操作。
------解决方案--------------------