-
Gesamte Inhalte
4 -
Benutzer seit
-
Letzter Besuch
Reputationsaktivitäten
-
inteldenim hat eine Reaktion von Gurki erhalten in Knobelaufgabe SED
Hallo, ungetestet.
public void AppendHostnamesToHostsFile(string filePath) { string[] lines = File.ReadAllLines(filePath); List<string> updatedLines = new List<string>(); foreach (string line in lines) { if (!string.IsNullOrWhiteSpace(line) && !line.Contains('#')) // Leere Zeilen, Kommentare skippen { var parts = line.Split(' '); if (parts.Length == 2 && parts[1].Contains(".")) { string ip = parts[0]; string fullName = parts[1]; // FQDN string shortName = fullName.Split('.')[0]; // Hostname updatedLines.Add($"{ip} {fullName} {shortName}"); } else { updatedLines.Add(line); //Sonstige Zeilen unverändert } } } File.WriteAllLines(filePath, updatedLines.ToArray()); }
-
inteldenim hat eine Reaktion von Dr. Octagon erhalten in Knobelaufgabe SED
Hallo, ungetestet.
public void AppendHostnamesToHostsFile(string filePath) { string[] lines = File.ReadAllLines(filePath); List<string> updatedLines = new List<string>(); foreach (string line in lines) { if (!string.IsNullOrWhiteSpace(line) && !line.Contains('#')) // Leere Zeilen, Kommentare skippen { var parts = line.Split(' '); if (parts.Length == 2 && parts[1].Contains(".")) { string ip = parts[0]; string fullName = parts[1]; // FQDN string shortName = fullName.Split('.')[0]; // Hostname updatedLines.Add($"{ip} {fullName} {shortName}"); } else { updatedLines.Add(line); //Sonstige Zeilen unverändert } } } File.WriteAllLines(filePath, updatedLines.ToArray()); }