JeBe came across a rather innovative way of determining if the codebase is running in a development or production enviornment. The logic goes, if there are two IP addresses, and one of them is 127.0.0.1, then it must be a development machine. And how do you check what the IP addresses are? It's quite simple, actually ...
private static string LocalAddress { get { string local = null; MatchCollection Mx =
Regex.Matches(RunCommand("cmd", "/c ipconfig"),
"IP Address[^:]+: ([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)",
RegexOptions.Singleline|RegexOptions.IgnoreCase); if(Mx!=null) { foreach(Match Mc in Mx) { if(Mc.Groups.Count==2&&Mc.Groups[1].Value!="127.0.0.1")
local = Mc.Groups[1].Value; } } return local; } }private static string RunCommand (string Command, string Parameters) { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Command; psi.Arguments = Parameters; psi.RedirectStandardOutput = true; psi.UseShellExecute = false; Process p = Process.Start (psi); StreamReader sr = p.StandardOutput; string s = sr.ReadToEnd(); sr.Close(); return s.Replace("\r\n", "\n"); }
Although, I think the author used the System.Net namespace and iterated through Dns.GetHostByName(Dns.GetHostName()).AddressList, we still may have had a WTF ...
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!