Tidied GetIPv4Address, it does return the ip if an ip is passed
This commit is contained in:
parent
e1776f8d01
commit
cfd2fdcb67
2 changed files with 7 additions and 12 deletions
|
|
@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
[assembly: AssemblyVersion("2.3.4.0716")]
|
||||
[assembly: AssemblyFileVersion("2.3.4.0716")]
|
||||
[assembly: AssemblyVersion("2.3.4.0719")]
|
||||
[assembly: AssemblyFileVersion("2.3.4.0719")]
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
|
|
@ -479,16 +480,10 @@ namespace TShockAPI
|
|||
/// <param name="hostname">string ip</param>
|
||||
public static string GetIPv4Address(string hostname)
|
||||
{
|
||||
string IP4Address = String.Empty;
|
||||
foreach (IPAddress IPA in Dns.GetHostAddresses(hostname))
|
||||
{
|
||||
if (IPA.AddressFamily.ToString() == "InterNetwork")
|
||||
{
|
||||
IP4Address = IPA.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return IP4Address;
|
||||
//Get the ipv4 address from GetHostAddresses, if an ip is passed it will return that ip
|
||||
var ip = Dns.GetHostAddresses(hostname).FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork);
|
||||
//if the dns query was successful then return it, otherwise return an empty string
|
||||
return ip != null ? ip.ToString() : "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue