开发者

using ip address component C#

开发者 https://www.devze.com 2023-01-11 07:32 出处:网络
I am trying to use a component which named as A C# IP Address Control but it has a problem I think. because when I increase its value 1, it gives me some wrong result. forexample

I am trying to use a component which named as A C# IP Address Control but it has a problem I think. because when I increase its value 1, it gives me some wrong result. forexample

ipAddressControl3.Text = "192.168.1.25";
IPAddress ipAddress1 = new IPAddress(ipAddressControl3.GetAddressBytes());
ipAddress1.Address++;
MessageBox.Show(ipAddress1.ToString());

returns : "193.168.1.25" ! but I expect 开发者_StackOverflow中文版"192.168.1.26"

what is the problem ?

here is the components link : A C# IP Address Control

edit : Maybe solution like this but I couldnt implemented it..


I convert my ip big endian to little like this :

int ipaddress= IPAddress.NetworkToHostOrder(BitConverter.ToInt32(IPAddress.Parse(ipAddressControl3.Text).GetAddressBytes(), 0));

and it work.


IP address are stored in network byte order (big-endian), whereas integers on Intel platforms are little-endian.


Try this:

ipAddressControl3.Text = "192.168.1.25";

byte[] ip = ipAddressControl3.GetAddressBytes();
ip[3] = (byte) (++ip[3]);

IPAddress ipAddress1 = new IPAddress(ip);
MessageBox.Show(ipAddress1.ToString());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号