As you have probably noticed, the ports for the League Ingame Api are random (before always 2999).
This was probably not intended by Riot. When a patch will be released is still written in the stars.

The code is not written properly, but it works.
It is not a beauty contest. It's just a workaround until the next patch.
To get the port for the ingame API you can use the following code:
Code:
private String GetPort()
{
var processes = Process.GetProcessesByName("League of Legends");
using (var ns = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo("netstat.exe", "-ano");
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
ns.StartInfo = psi;
ns.Start();
using (StreamReader r = ns.StandardOutput)
{
string output = r.ReadToEnd();
ns.WaitForExit();
string[] lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
foreach (string line in lines)
{
if (line.Contains(processes[0].Id.ToString()) && line.Contains("0.0.0.0:0"))
{
var outp = line.Split(' ');
return outp[6].Replace("127.0.0.1:", "");
}
}
}
}
return String.Empty;
}






