Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Fixed invisible on creds prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
VarChar42 committed Jan 27, 2022
1 parent 7687008 commit 929fcb1
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions InternetPLS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Windows.Forms;

#endregion
Expand Down Expand Up @@ -36,6 +37,7 @@ private static void Main(string[] args)
}
else
{
VisibilityManager.ShowWindow();
string username = ConsoleUtils.Prompt("Username > ");
string pw = ConsoleUtils.SecretPrompt("Password > ");

Expand All @@ -51,40 +53,57 @@ private static void Main(string[] args)
File.WriteAllText(CredentialsFile, content);
}

NetworkInterface? htlgkrInterface = null;
IPAddress? htlgkrAddress = null;
IPAddress htlgkrAddress;

foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
while (true)
{
string dnsSuffix = networkInterface.GetIPProperties().DnsSuffix;
if (dnsSuffix.Equals("htl.grieskirchen.local") && networkInterface.OperationalStatus == OperationalStatus.Up)
htlgkrAddress = FindHtlAddress();
if (htlgkrAddress != null)
{
htlgkrInterface = networkInterface;
break;
}
Console.WriteLine("HTL network not found. Retrying in 5s ...");
VisibilityManager.ShowWindow();
Thread.Sleep(5000);
}

if (htlgkrInterface != null)
VisibilityManager.HideWindow();

var login = new PostLogin(loginData, htlgkrAddress);
login.Login();

var watchdog = new Watchdog(login);
watchdog.Start();

Application.Run();
}

private static IPAddress FindHtlAddress()
{
NetworkInterface htlgkrInterface = null;
IPAddress htlgkrAddress = null;

foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (UnicastIPAddressInformation ipInfo in htlgkrInterface.GetIPProperties().UnicastAddresses)
string dnsSuffix = networkInterface.GetIPProperties().DnsSuffix;
if (dnsSuffix.Equals("htl.grieskirchen.local") && networkInterface.OperationalStatus == OperationalStatus.Up)
{
if (ipInfo.Address.IsIPv6LinkLocal) continue;
htlgkrAddress = ipInfo.Address;
Console.WriteLine($"Using network: {ipInfo.Address}");
htlgkrInterface = networkInterface;
break;
}
}

var login = new PostLogin(loginData, htlgkrAddress!);
login.Login();
if (htlgkrInterface == null)
return null;

var watchdog = new Watchdog(login);
watchdog.Start();
}
else
foreach (UnicastIPAddressInformation ipInfo in htlgkrInterface.GetIPProperties().UnicastAddresses)
{
Console.WriteLine("HTL network not found. (Press any key to abort)");
if (ipInfo.Address.IsIPv6LinkLocal) continue;
htlgkrAddress = ipInfo.Address;
Console.WriteLine($"Using network: {ipInfo.Address}");
}

Application.Run();
return htlgkrAddress;
}
}
}

0 comments on commit 929fcb1

Please sign in to comment.