void IGXDLMSBase.Save(GXXmlWriter writer) { writer.WriteElementString("DataLinkLayerReference", DataLinkLayerReference, 2); writer.WriteElementString("IPAddress", IPAddress.ToString(), 3); writer.WriteStartElement("MulticastIPAddress", 4); if (MulticastIPAddress != null) { foreach (IPAddress it in MulticastIPAddress) { writer.WriteElementString("Value", it.ToString(), 4); } } writer.WriteEndElement(); writer.WriteStartElement("IPOptions", 5); if (IPOptions != null) { foreach (GXDLMSIp4SetupIpOption it in IPOptions) { writer.WriteStartElement("IPOption", 5); writer.WriteElementString("Type", (int)it.Type, 5); writer.WriteElementString("Length", it.Length, 5); writer.WriteElementString("Data", GXDLMSTranslator.ToHex(it.Data), 5); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteElementString("SubnetMask", SubnetMask.ToString(), 6); writer.WriteElementString("GatewayIPAddress", GatewayIPAddress.ToString(), 7); writer.WriteElementString("UseDHCP", UseDHCP, 8); writer.WriteElementString("PrimaryDNSAddress", PrimaryDNSAddress.ToString(), 9); writer.WriteElementString("SecondaryDNSAddress", SecondaryDNSAddress.ToString(), 10); }
public SubnetMask ToSubnetMask() { SubnetMask subnet = new SubnetMask(); for (int i = 0; i < _octet.Length; i++) subnet.Octet[i].Decimal = 255 - _octet[i].Decimal; return subnet; }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns> /// <autogeneratedoc /> public override int GetHashCode() { unchecked { var hashCode = IPAddress != null?IPAddress.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (SubnetMask != null ? SubnetMask.GetHashCode() : 0); return(hashCode); } }
private void GotFocusReset(object sender, RoutedEventArgs e) { TextBox textBox = sender as TextBox; FirstIP.ClearValue(Label.ContentProperty); LastIP.ClearValue(Label.ContentProperty); SubnetMask.ClearValue(Label.ContentProperty); nHosts.ClearValue(Label.ContentProperty); textBox.GotFocus -= GotFocusReset; }
public override int GetHashCode() { if (_hashCode == null) { unchecked { _hashCode = ((Address?.GetHashCode() ?? 0) * 397) ^ (SubnetMask?.GetHashCode() ?? 0); } } return(_hashCode.Value); }
/// <summary> /// Returns a string that represents the current <see cref="NetworkAddress" />. /// </summary> /// <returns> /// A string that represents the current <see cref="NetworkAddress" />. /// </returns> public override string ToString() { if (Equals(LocalSubnet)) { return("LocalSubnet"); } if (SubnetMask.Equals(IPAddress.None)) { return(Address.ToString()); } return($"{Address}/{SubnetMask}"); }
internal byte[] ToArray() { var ret = new byte[27]; IP.GetAddressBytes().CopyTo(ret, 0); SubnetMask.GetAddressBytes().CopyTo(ret, 4); MacAddress.GetAddressBytes().CopyTo(ret, 8); DefaultGateway.GetAddressBytes().CopyTo(ret, 14); Server.GetAddressBytes().CopyTo(ret, 18); ret[22] = FarLimit; Bytes.Write(2, ComPort).CopyTo(ret, 23); ret[25] = (byte)TcpMode; ret[26] = (byte)(DhcpEnabled ? 1 : 0); return(ret); }
public int Serialize(System.IO.Stream buffer) { int ret = 0; byte[] tmp; tmp = Ip.GetAddressBytes(); buffer.Write(tmp, 0, tmp.Length); ret += tmp.Length; tmp = SubnetMask.GetAddressBytes(); buffer.Write(tmp, 0, tmp.Length); ret += tmp.Length; tmp = Gateway.GetAddressBytes(); buffer.Write(tmp, 0, tmp.Length); ret += tmp.Length; return(ret); }
public int GetMaskSize() { int output = 0; var bytes = SubnetMask.GetAddressBytes(); foreach (var b in bytes) { foreach (char c in Convert.ToString(b, 2).PadLeft(8, '0').ToCharArray()) { if (c.Equals('1')) { output++; } } } return(output); }
private void SplitSubnets() { if (Mask == null || Ip == null) { return; } var buffer = new StringBuilder(); int requiredbits = GetBits(NetworkCount); int maskbits = SubnetMask.GetBitLength(Mask); int outmaskbits = requiredbits + maskbits; if (outmaskbits > 32) { buffer.AppendLine("IPv4 is too small for this"); Output = buffer.ToString(); OnPropertyChanged(() => Output); return; } buffer.AppendFormat("Required additional subnet bits for {0} networks: {1}\r\n", NetworkCount, requiredbits); buffer.AppendFormat("New netmask: {0}/{1}\r\n", SubnetMask.CreateByNetBitLength(outmaskbits), outmaskbits); buffer.AppendLine("--------------------------------------------------------------------------------------"); buffer.AppendLine(); uint tmp = Ip.GetUint(); int shift = 32 - outmaskbits; for (uint i = 0; i < NetworkCount; i++) { uint sh = i << shift; uint val = tmp + sh; var addr = new IPAddress(0); addr = addr.SetUint(val); buffer.AppendFormat("Subnet {0,-4} Network adress: {1,-15} Broadcast Adress: {2,-15}\r\n", i, addr, addr.GetBroadcastAddress(SubnetMask.CreateByNetBitLength(outmaskbits))); } Output = buffer.ToString(); OnPropertyChanged(() => Output); }
private void Button_Click(object sender, RoutedEventArgs e) { Output.Clear(); if (Network.IP == null || Mask.IP == null) { return; } int numnet = (int)ReqNetworks.Value; StringBuilder buffer = new StringBuilder(); int requiredbits = GetBits(numnet); int maskbits = SubnetMask.GetBitLength(Mask.IP); int outmaskbits = requiredbits + maskbits; if (outmaskbits > 32) { buffer.AppendLine("IPv4 is too small for this"); Output.Text = buffer.ToString(); return; } buffer.AppendFormat("Required additional subnet bits for {0} networks: {1}\r\n", numnet, requiredbits); buffer.AppendFormat("New netmask: {0}/{1}\r\n", SubnetMask.CreateByNetBitLength(outmaskbits), outmaskbits); buffer.AppendLine("--------------------------------------------------------------------------------------"); buffer.AppendLine(); uint tmp = Network.IP.GetUint(); int shift = 32 - outmaskbits; for (uint i = 0; i < numnet; i++) { uint sh = i << shift; uint val = tmp + sh; IPAddress addr = new IPAddress(0); addr = addr.SetUint(val); buffer.AppendFormat("Subnet {0,-4} Network adress: {1,-15} Brodecast Adress: {2,-15}\r\n", i, addr, addr.GetBroadcastAddress(SubnetMask.CreateByNetBitLength(outmaskbits))); } Output.Text = buffer.ToString(); }
private void AndValues_Click(object sender, RoutedEventArgs e) { try { string IpAddressInput = IpAddressTextBox.Text; string SubnetmaskInput = SubnetMaskTextBox.Text; Ander AddressAnder = new Ander(); IpAddress InputIpAddress = new IpAddress(IpAddressInput); SubnetMask InputNetmask = new SubnetMask(SubnetmaskInput); IpAddress AndedAddress = AddressAnder.AndAddress(InputIpAddress, InputNetmask); OutputTextBox.Text = AndedAddress.ToString(); } catch (Exception) { Helpers.MessageBox MessageBox = new Helpers.MessageBox("Invalid input"); MessageBox.Show(); } }
private void Initiate() { var byteMask = new List <byte>(); var byteIP = new List <byte>(); var byteStart = new List <byte>(); foreach (var item in SubnetMask.Split('.')) { byteMask.Add(Byte.Parse(item)); } foreach (var item in IPv4.Split('.')) { byteIP.Add(Byte.Parse(item)); } for (int i = 0; i < byteIP.Count; i++) { byteStart.Add((byte)(byteIP[i] & byteMask[i])); } foreach (var item in byteStart) { StartPosIP += item.ToString() + "."; } StartPosIP = StartPosIP.Remove(StartPosIP.Length - 1); string temp = ""; foreach (var item in byteMask) { temp += Convert.ToString(item, 2).PadLeft(8, '0'); } temp = temp.Replace('1', ' ').Trim(); Amount = (int)Math.Pow(2, (double)(temp.Length)) - 2; }
public override bool Equals(object obj) { Adapter a; try { a = (Adapter)obj; } catch (InvalidCastException) { return(false); } if (MyMACAddress == null) { if (a.MyMACAddress != null) { return(false); } } else if (!MyMACAddress.Equals(a.MyMACAddress)) { return(false); } if (LocalIP == null) { if (a.LocalIP != null) { return(false); } } else if (!LocalIP.Equals(a.LocalIP)) { return(false); } if (SubnetMask == null) { if (a.SubnetMask != null) { return(false); } } else if (!SubnetMask.Equals(a.SubnetMask)) { return(false); } if (DefaultGateway == null) { if (a.DefaultGateway != null) { return(false); } } else if (!DefaultGateway.Equals(a.DefaultGateway)) { return(false); } if (DNS == null) { if (a.DNS != null) { return(false); } } else if (!DNS.Equals(a.DNS)) { return(false); } if ((Name == a.Name) && (OtherEndID == a.OtherEndID) && (Connected == a.Connected) && (Associated == a.Associated)) { return(true); } return(false); }
public override int GetHashCode() { return(2 * BaseAddress.GetHashCode() + 3 * SubnetMask.GetHashCode()); }
void ReleaseDesignerOutlets() { if (NetworkUpdateButton != null) { NetworkUpdateButton.Dispose(); NetworkUpdateButton = null; } if (Authentication != null) { Authentication.Dispose(); Authentication = null; } if (BootFileLabel != null) { BootFileLabel.Dispose(); BootFileLabel = null; } if (ConfigFileLabel != null) { ConfigFileLabel.Dispose(); ConfigFileLabel = null; } if (DefaultGateway != null) { DefaultGateway.Dispose(); DefaultGateway = null; } if (DeployButton != null) { DeployButton.Dispose(); DeployButton = null; } if (DeviceType != null) { DeviceType.Dispose(); DeviceType = null; } if (EnableDHCP != null) { EnableDHCP.Dispose(); EnableDHCP = null; } if (EncryptConfig != null) { EncryptConfig.Dispose(); EncryptConfig = null; } if (Encryption != null) { Encryption.Dispose(); Encryption = null; } if (FirmwareStatus != null) { FirmwareStatus.Dispose(); FirmwareStatus = null; } if (FlashFileLabel != null) { FlashFileLabel.Dispose(); FlashFileLabel = null; } if (FreeSlots != null) { FreeSlots.Dispose(); FreeSlots = null; } if (MacAddress != null) { MacAddress.Dispose(); MacAddress = null; } if (NetworkKey != null) { NetworkKey.Dispose(); NetworkKey = null; } if (NetworkMacAddress != null) { NetworkMacAddress.Dispose(); NetworkMacAddress = null; } if (NetworkValue != null) { NetworkValue.Dispose(); NetworkValue = null; } if (Output != null) { Output.Dispose(); Output = null; } if (Passphrase != null) { Passphrase.Dispose(); Passphrase = null; } if (PrimaryDNS != null) { PrimaryDNS.Dispose(); PrimaryDNS = null; } if (RadioA != null) { RadioA.Dispose(); RadioA = null; } if (RadioB != null) { RadioB.Dispose(); RadioB = null; } if (RadioG != null) { RadioG.Dispose(); RadioG = null; } if (RadioN != null) { RadioN.Dispose(); RadioN = null; } if (ReKeyInternal != null) { ReKeyInternal.Dispose(); ReKeyInternal = null; } if (SaveConfigurationButton != null) { SaveConfigurationButton.Dispose(); SaveConfigurationButton = null; } if (SecondaryDNS != null) { SecondaryDNS.Dispose(); SecondaryDNS = null; } if (SSID != null) { SSID.Dispose(); SSID = null; } if (StaticIPAddress != null) { StaticIPAddress.Dispose(); StaticIPAddress = null; } if (SubnetMask != null) { SubnetMask.Dispose(); SubnetMask = null; } if (UpdateFirmwareButton != null) { UpdateFirmwareButton.Dispose(); UpdateFirmwareButton = null; } }
public override string ToString() { return("{" + Ip.ToString() + " - " + SubnetMask.ToString() + " - " + Gateway.ToString() + "}"); }
/// <summary> /// 文字列配列型のサブネットマスクを取得します。 /// </summary> public string[] GetSubnetMaskStringArray() => SubnetMask == null ? new string[] { "255.255.255.0" } : new string[] { SubnetMask.ToString() };
/// <summary> /// Compares two network address. /// </summary> /// <returns> /// <see langword="true" /> if the two network address are equal; otherwise, <see langword="false" />. /// </returns> /// <param name="comparand">An <see cref="NetworkAddress" /> instance to compare to the current instance. </param> protected bool Equals(NetworkAddress comparand) { return(Address.Equals(comparand.Address) && SubnetMask.Equals(comparand.SubnetMask)); }