Add functions to the IP address. We need to use them and then test, test, test...
This commit is contained in:
parent
fdc3877e4f
commit
2f63aacecd
@ -24,11 +24,13 @@ namespace EduNetworkBuilder
|
||||
private IPAddress theNetmask;
|
||||
private IPAddress theGateway;
|
||||
|
||||
private bool Unset = true;
|
||||
|
||||
public NB_IPAddress() { } //used for reflection
|
||||
/// <summary>
|
||||
/// Duplicate an IP address structure
|
||||
/// </summary>
|
||||
/// <param name="Orig"></param>
|
||||
/// <param name="Orig">The IP to clone from</param>
|
||||
public NB_IPAddress(NB_IPAddress Orig)
|
||||
{
|
||||
_ip = Orig._ip;
|
||||
@ -38,22 +40,42 @@ namespace EduNetworkBuilder
|
||||
theIP = Orig.theIP;
|
||||
theNetmask = Orig.theNetmask;
|
||||
theGateway = Orig.theGateway;
|
||||
Unset = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a simple IP address with netmask
|
||||
/// </summary>
|
||||
/// <param name="ip">The new IP</param>
|
||||
/// <param name="mask">The new netmask</param>
|
||||
/// <param name="WhatType"></param>
|
||||
public NB_IPAddress(string ip, string mask, IPAddressType WhatType)
|
||||
{
|
||||
myType = WhatType;
|
||||
_ip = ip.ParseIp();
|
||||
_mask = mask.ParseIp();
|
||||
Unset = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a new IP address, netmask, with gateway.
|
||||
/// </summary>
|
||||
/// <param name="ip">The IP address</param>
|
||||
/// <param name="mask">The netmask</param>
|
||||
/// <param name="gw">The gateway to use</param>
|
||||
public NB_IPAddress(string ip, string mask, string gw)
|
||||
{
|
||||
myType = IPAddressType.route;
|
||||
_ip = ip.ParseIp();
|
||||
_mask = mask.ParseIp();
|
||||
_gw = gw.ParseIp();
|
||||
Unset = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an IP address from the XML file
|
||||
/// </summary>
|
||||
/// <param name="theNode">The XmlNode to load from</param>
|
||||
public NB_IPAddress(XmlNode theNode)
|
||||
{
|
||||
foreach (XmlNode Individual in theNode.ChildNodes)
|
||||
@ -65,12 +87,15 @@ namespace EduNetworkBuilder
|
||||
{
|
||||
case "ip":
|
||||
_ip = Individual.InnerText.ParseIp();
|
||||
Unset = false;
|
||||
break;
|
||||
case "mask":
|
||||
_mask = Individual.InnerText.ParseIp();
|
||||
Unset = false;
|
||||
break;
|
||||
case "gateway":
|
||||
_gw = Individual.InnerText.ParseIp();
|
||||
Unset = false;
|
||||
break;
|
||||
case "type":
|
||||
myType = NB.ParseEnum<IPAddressType>(Individual.InnerText);
|
||||
@ -82,7 +107,8 @@ namespace EduNetworkBuilder
|
||||
|
||||
public void SetIP(UInt32 newIP)
|
||||
{
|
||||
_ip = newIP;
|
||||
_ip = newIP;
|
||||
Unset = false;
|
||||
}
|
||||
|
||||
public bool Equals(NB_IPAddress CompareWith)
|
||||
@ -109,11 +135,13 @@ namespace EduNetworkBuilder
|
||||
_ip = ip.ParseIp();
|
||||
_mask = mask.ParseIp();
|
||||
_gw = gw.ParseIp();
|
||||
Unset = false;
|
||||
}
|
||||
public void Reparse(string ip, string mask)
|
||||
{
|
||||
_ip = ip.ParseIp();
|
||||
_mask = mask.ParseIp();
|
||||
Unset = false;
|
||||
}
|
||||
|
||||
public IPAddressType GetAddressType
|
||||
@ -298,6 +326,53 @@ namespace EduNetworkBuilder
|
||||
return false;
|
||||
}
|
||||
|
||||
#region IP Status Funcs
|
||||
/// <summary>
|
||||
/// If the IP address has not yet been assigned
|
||||
/// </summary>
|
||||
public bool IsUnassigned() { return Unset; }
|
||||
|
||||
/// <summary>
|
||||
/// If the IP address is the same as the broadcast address
|
||||
/// </summary>
|
||||
public bool IsBroadcast()
|
||||
{
|
||||
uint BA = BroadcastAddress;
|
||||
if (_ip == BA) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// If the IP address is the same as the network address
|
||||
/// </summary>
|
||||
public bool IsNetwork()
|
||||
{
|
||||
uint NA = NetworkAddress;
|
||||
if (_ip == NA) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the IP address is the loopback address. Different for IPv4 than IPv6
|
||||
/// </summary>
|
||||
public bool IsLoopback()
|
||||
{
|
||||
if (GetIPString == "127.0.0.1") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// If the IP address is 0.0.0.0 or the equavelent
|
||||
/// </summary>
|
||||
/// <returns>true if it is zeroes could be unset or anywhere</returns>
|
||||
public bool IsZeroString() {
|
||||
if (_ip == 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Break an IP
|
||||
public string GenRandomIPOrMask()
|
||||
|
Loading…
Reference in New Issue
Block a user