获得本地主机IP
IPHostEntry myHost=new IPHostEntry();
myHost=Dns.GetHostByName(Dns.GetHostName());
string hostName=myHost.HostName.ToString().Trim();
myHostIP=myHost.AddressList[0].ToString().Trim();//得到主机IP
MessageBox.Show(hostName.ToString()+myHostIP.ToString());
string[] IP=myHostIP.Split('.');
myIPUse=IP[0].ToString().Trim()+"."+IP[1].ToString().Trim()+"."+IP[2].ToString().Trim()+".";//得到IP前段
//开线程
Thread[] myThread=new Thread[255]; //255个线程
for (int i=1;i <=255;i++)
{
int k = 255-i ;
ping HostPing = new ping() ; //创建一个ping实例
HostPing.ip = myIPUse + i.ToString() ;
HostPing.ul = new UpdateList(UpdateMyList) ; //向这个ping实例中传递IP地址字符串
myThread[k] = new Thread( new ThreadStart( HostPing.scan )) ; //启动线程
myThread[k].Start() ;
}
myHost=Dns.GetHostByName(Dns.GetHostName());
string hostName=myHost.HostName.ToString().Trim();
myHostIP=myHost.AddressList[0].ToString().Trim();//得到主机IP
MessageBox.Show(hostName.ToString()+myHostIP.ToString());
string[] IP=myHostIP.Split('.');
myIPUse=IP[0].ToString().Trim()+"."+IP[1].ToString().Trim()+"."+IP[2].ToString().Trim()+".";//得到IP前段
//开线程
Thread[] myThread=new Thread[255]; //255个线程
for (int i=1;i <=255;i++)
{
int k = 255-i ;
ping HostPing = new ping() ; //创建一个ping实例
HostPing.ip = myIPUse + i.ToString() ;
HostPing.ul = new UpdateList(UpdateMyList) ; //向这个ping实例中传递IP地址字符串
myThread[k] = new Thread( new ThreadStart( HostPing.scan )) ; //启动线程
myThread[k].Start() ;
}