Skip to content

Instantly share code, notes, and snippets.

@thebitbrine
Created January 13, 2020 08:41
Show Gist options
  • Save thebitbrine/958e20909ea6faef77dd3d47099d9182 to your computer and use it in GitHub Desktop.
Save thebitbrine/958e20909ea6faef77dd3d47099d9182 to your computer and use it in GitHub Desktop.
Generates static port number by assembly name.
public static int AutoPort()
{
string assemName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
byte[] ba = System.Text.Encoding.Default.GetBytes(assemName);
string oPort = ba[0].ToString() + ba[ba.Length - 1].ToString() + ba[ba.Length/2] * 100;
while (long.Parse(oPort) >= 65535)
oPort = oPort.Substring(oPort.Length / 2, 4);
return int.Parse(oPort);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment