using System.Net;
using System.Windows.Forms;
namespace NetWorkHelper.ICommond
{
public class CommonMethod
{
///
/// 域名转换为IP地址
///
/// 域名或IP地址
/// IP地址
internal static string HostnameToIp(string hostname)
{
try
{
IPAddress ip;
if (IPAddress.TryParse(hostname, out ip))
return ip.ToString();
else
return Dns.GetHostEntry(hostname).AddressList[0].ToString();
}
catch
{
throw;
}
}
///
/// 外部调用是否需要用Invoket
///
/// 事件参数
internal static void EventInvoket(Action func)
{
Form form = null;
if (Application.OpenForms.Count > 0)
{
form = Application.OpenForms[0];
}
//Form form = Application.OpenForms.Cast