IPAddress[] ips=Dns.GetHostAddress("www.baidu.com"); //ips为主机ip地址
foreach(IPAddress ip in ips) ip为ip地址
{
string i=ip.ToString(); Dns.GetHostName();//本机名
}
--------------------------------------------
IPAddress[] ips =Dns.GetHostAddress("192.168.1.97");
foreach (IPAddress ip in ips)
{
}
-------------------------------------------
IPEndPoint ipendpoint =new IPEndPoint("192.168.1.97“,80);
----------------------------------------------
Socket socket=null;
IPHostEntry iphostentry=null;
iphosstentry=Dns.GetHostEntry(server);
foreach(IPAddress address in iphostentry.AddressList)
{
IPEndPoint ipendpoint=new IPEndPoint(address ,port);
Socket newSocket=new Socket(ipendpoint .AddressFamily,SocketType.Stream,ProtocolType.Tcp);
newSocket.Connect(ipendpoint );
if(newSocket.Connect)
{
socket=newSocket;
break;
}
else{
continue;
}
return socket;
}
------------------------------------------------------------------
TcpListener tpclistener=new TcpListener("192.168.1.98",80);
tcplistener.Start();
foreach(IPAddress ip in ips) ip为ip地址
{
string i=ip.ToString(); Dns.GetHostName();//本机名
}
--------------------------------------------
IPAddress[] ips =Dns.GetHostAddress("192.168.1.97");
foreach (IPAddress ip in ips)
{
}
-------------------------------------------
IPEndPoint ipendpoint =new IPEndPoint("192.168.1.97“,80);
----------------------------------------------
Socket socket=null;
IPHostEntry iphostentry=null;
iphosstentry=Dns.GetHostEntry(server);
foreach(IPAddress address in iphostentry.AddressList)
{
IPEndPoint ipendpoint=new IPEndPoint(address ,port);
Socket newSocket=new Socket(ipendpoint .AddressFamily,SocketType.Stream,ProtocolType.Tcp);
newSocket.Connect(ipendpoint );
if(newSocket.Connect)
{
socket=newSocket;
break;
}
else{
continue;
}
return socket;
}
------------------------------------------------------------------
TcpListener tpclistener=new TcpListener("192.168.1.98",80);
tcplistener.Start();