private void btnLookUpIpV4_Click(object sender, EventArgs e) { string lookup = txtName.Text; if (lookup.Length > 0) { string[] ipv4 = WOL2DNSHelper.ResolveToIPv4(lookup); if (ipv4 == null || ipv4.Length == 0) { string msg = MOE.Utility.GetStringFromRes("strHostnameInValid"); MessageBox.Show(this, msg, "Wake on lan tool 2", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } contextMenuStrip1.Items.Clear(); foreach (string s in ipv4) { contextMenuStrip1.Items.Add(s); } contextMenuStrip1.Show(this.Left + btnLookUpIpV4.Left, this.Top + btnLookUpIpV4.Bottom); } }
/// <summary> /// Expands the given string using placeholder variables /// </summary> /// <param name="sFormat">The format string to expand.</param> /// <returns>The expanded string.</returns> public string ExpandVariables(string what) { String s = what; s = s.Replace("%name%", GetName()); s = s.Replace("%ip%", GetIpAddress()); s = s.Replace("%ipv6%", GetIpV6Address()); s = s.Replace("%mac%", GetMacAddress()); s = s.Replace("%comment%", GetDescription()); s = s.Replace("%snmask%", GetSubnetMask()); s = s.Replace("%groups%", GetGroups()); s = s.Replace("%state%", StateAsString()); s = s.Replace("%dname%", IsDynamicHost() ? GetName() : GetIpAddress()); try { if (s.IndexOf("%dipv4%") >= 0) { s = s.Replace("%dipv4%", WOL2DNSHelper.ResolveToIPv4(GetName())[0]); } } catch { } try { if (s.IndexOf("%dipv6%") >= 0) { s = s.Replace("%dipv6%", WOL2DNSHelper.ResolveToIPv6Local(GetName())); } } catch { } return(s); }