How to using IPAddress.Parse Method
This should work using System.Net.IPAddress.
;
1 |
<span class="typ">System</span><span class="pun">.</span><span class="typ">Net</span><span class="pun">.</span><span class="typ">IPAddress</span><span class="pln"> ipaddress </span><span class="pun">=</span> <span class="typ">System</span><span class="pun">.</span><span class="typ">Net</span><span class="pun">.</span><span class="typ">IPAddress</span><span class="pun">.</span><span class="typ">Parse</span><span class="pun">(</span><span class="str">"127.0.0.1"</span><span class="pun">);</span> <span class="com">//127.0.0.1 as an example</span> |
Example:
The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address. For example:
Number of parts and example ipString | IPv4 address for IPAddress |
---|---|
1 — “65536” | 0.0.255.255 |
2 — “20.2” | 20.0.0.2 |
2 — “20.65535” | 20.0.255.255 |
3 — “128.1.2” | 128.1.0.2 |