日期:2014-05-17 浏览次数:21254 次
//获取本地计算机IP,计算机名称
IPHostEntry IPHost = Dns.Resolve(Environment.MachineName);
if (IPHost.AddressList.Length > 0)
{
strHostIP = IPHost.AddressList[0].ToString();
}
else
{
return;
}
//通过IP来获取计算机名称,可用在局域网内
IPHostEntry ipHostEntry = Dns.GetHostByAddress(strHostIP);
strHostName=ipHostEntry.HostName.ToString();
//获取本地计算机上的OPCServerName
try
{
KepServer = new OPCServer();
object serverList = KepServer.GetOPCServers(strHostName);
foreach (string turn in (Array)serverList)
{
cmbServerName.Items.Add(turn);
}
cmbServerName.SelectedIndex = 0;
btnConnServer.Enabled = true;
}
catch(Exception err)