To check the Valid IP Address in
c#
What is IP
Address (Taken from Wikipedia) : -
An Internet Protocol address (also
known as an IP
address) is a numerical label assigned to each device
(e.g., computer, printer) participating in a computer network that
uses the Internet Protocol for
communication. An IP address serves two principal
functions: host or network interface identification and location addressing. Its
role has been characterized as follows: "A name indicates
what we seek. An address indicates where it is. A route indicates how to get
there.
In
IPv4 an address consists of 32 bits which limits the address space to 4294967296 (232) possible unique
addresses. IPv4 reserves some addresses for special purposes such as private networks (~18 million addresses) or multicast addresses (~270 million addresses).
IPv4
addresses are canonically represented in dot-decimal
notation, which consists of four decimal numbers, each ranging from
0 to 255, separated by dots, e.g., 172.16.254.1. Each part represents a group
of 8 bits (octet) of
the address. In some cases of technical writing, IPv4 addresses may be
presented in various hexadecimal, octal,
or binary representations.
A
valid IP address must be in the form of xxx.xxx.xxx.xxx, where xxx is a number
from 0-255. There are a few reserved addresses has cannot be used. 10.x.x.x
cannot be used along with 192.168.x.x, 172.16.0.0 to 172.31.255.255.
Program
to find out the valid IP Address:-
/// <summary>
/// to check the Valid IP Address.
/// </summary>
private bool IsValidIPList(out IPAddress ipAddress)
{
bool isIPValid = false;
ipAddress = null;
// for
checking how many "." is available in the given textbox.
List<string> lstIP = txtPOSLynxIP.Text.Trim().Split('.').ToList();
// if there is 4 ".", it means
valid dots in any IPAddress.
if (lstIP.Count == 4)
isIPValid = IPAddress.TryParse(txtPOSLynxIP.Text.Trim(),
out ipAddress);
return isIPValid;
}
|
No comments:
Post a Comment