Created
January 13, 2020 08:41
-
-
Save thebitbrine/958e20909ea6faef77dd3d47099d9182 to your computer and use it in GitHub Desktop.
Generates static port number by assembly name.
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
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