/// <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); }
private void button1_Click(object sender, EventArgs e) { string lookup = txtName.Text; if (lookup.Length > 0) { string ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup); if (ipv6 == null) { lookup = txtIp.Text; if (lookup.Length > 0) { ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup); } } if (ipv6 != null) { txtIPv6.Text = ipv6; } } }
/// <summary> /// This function scans a single host /// </summary> /// <param name="h">A WOL2Host containing the information /// required to scan a host.</param> /// <returns>True, if the host was successfully scanned.</returns> private bool ScanHost(WOL2Host h) { bool bRet = false; IPAddress ip = IPAddress.Parse(h.GetIpAddress()); byte[] buffer = new byte[32]; Ping myPing = new Ping(); PingOptions pingOptions = new PingOptions(); PingReply reply = myPing.Send(ip, m_iPingTimeout, buffer, pingOptions); // send the ping if (reply.Status == IPStatus.Success) { // Found a host // WOL2Host h = new WOL2Host(); try { h.SetIpAddress(ip.ToString()); h.SetMacAddress(WOL2DNSHelper.GetMACAddress(h.GetIpAddress())); h.SetName(Dns.GetHostEntry(h.GetIpAddress()).HostName); // ipv6 lookup string lookup = h.GetName(); string ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup); if (ipv6 == null) { lookup = h.GetIpAddress(); ipv6 = WOL2DNSHelper.ResolveToIPv6Local(lookup); } if (ipv6 != null) { h.SetIpV6Address(ipv6); } // check if the hostname was found bool bAdd = true; if (m_bAddIfHostnameResolved) { bAdd = (h.GetIpAddress() != h.GetName()); } if (m_bAddIfMacResolved) { bAdd = (h.GetMacAddress().Length != 0); } if (bAdd) { Monitor.Enter(Hosts); Hosts.Add(h); Monitor.Exit(Hosts); } MOE.Logger.DoLog("ScanHost(): Found host: " + h + ". " + (bAdd ? "Adding it." : "Not adding it."), MOE.Logger.LogLevel.lvlInfo); bRet = bAdd; } catch (System.Net.Sockets.SocketException se) { MOE.Logger.DoLog(se.ToString(), MOE.Logger.LogLevel.lvlWarning); } catch (Exception ex) { MOE.Logger.DoLog(ex.ToString(), MOE.Logger.LogLevel.lvlWarning); } } MOE.Logger.DoLog("ScanHost(): finished job " + h.GetIpAddress(), MOE.Logger.LogLevel.lvlDebug); return(bRet); }