-
-
Save ddevault/8377075da938b128bef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IPEndPoint ParseEndPoint(string arg) | |
{ | |
IPAddress address; | |
int port; | |
if (arg.Contains(':')) | |
{ | |
// Both IP and port are specified | |
var parts = arg.Split(':'); | |
if (!IPAddress.TryParse(parts[0], out address)) | |
address = Resolve(parts[0]); | |
return new IPEndPoint(address, int.Parse(parts[1])); | |
} | |
if (IPAddress.TryParse(arg, out address)) | |
return new IPEndPoint(address, 25565); | |
if (int.TryParse(arg, out port)) | |
return new IPEndPoint(IPAddress.Loopback, port); | |
return new IPEndPoint(Resolve(arg), 25565); | |
} | |
private static IPAddress Resolve(string arg) | |
{ | |
return Dns.GetHostEntry(arg).AddressList.FirstOrDefault(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment