Using C # ip address component

I am trying to use a component called A C # IP Address Control, but I have a problem, I think. because when I increase its value to 1, it gives me the 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 "192.168.1.26"

what is the problem?

here is the link to the components: C # IP Address Management

edit: Maybe a solution like this , but I could not implement it ..

+1
source share
3 answers

I convert my ip big endian to small like this:

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

and it works.

+2
source

IP- (big-endian), Intel .

+1

Try the following:

ipAddressControl3.Text = "192.168.1.25";

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

IPAddress ipAddress1 = new IPAddress(ip);
MessageBox.Show(ipAddress1.ToString());
+1
source

Source: https://habr.com/ru/post/1759662/


All Articles