用api判断:
vb.net的代码Public Module GetInternetState     
’ Declare the API function.   
Private Declare Function InternetGetConnectedState Lib "wininet" (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long 
’ Define the possible types of connections.  
Private Enum ConnectStates      
LAN = &H2      
Modem = &H1     
Proxy = &H4     
Offline = &H20  
Configured = &H40   
RasInstalled = &H10  
End Enum   
Public Sub Main()     
’ Get the connected status.    
Dim dwFlags As Long    
Dim Connected As Boolean = (InternetGetConnectedState(dwFlags, 0&) <> 0)
If Connected Then
Console.WriteLine("This computer is connected to the Internet.")
’ Display all connection flags.
Console.Write("Connection flags:") 
Dim ConnectionType As ConnectStates   
For Each ConnectionType In System.Enum.GetValues(GetType(ConnectStates))     
If (ConnectionType And dwFlags) = ConnectionType Then     
Console.Write(" " & ConnectionType.ToString())        
End If           
Next      
End If    
Console.ReadLine()   
End Sub End Module
A sample output is shown here:
This computer is connected to the Internet.Connection flags: LAN

解决方案 »

  1.   

    using MSXML2;
    try
    {
    XMLHTTP http = new XMLHTTP();
    http.open("GET", "http://www.sina.com.cn", false, null, null);
    http.send(null);}
    catch(Exception ex)
    {
    Console.WriteLine(ex.toString());
    }
      

  2.   

    我们通常的判断方法是先PING自己主机的环回地址127。0。0。1若可以,则说明你的TCP/IP配置正确,然后PING你的网关如果PING 不通就是你的网卡问题。如果通了再PING外面的网站来验证是不是可以上网。不知道你是不是要这个答案
      

  3.   

    我是想用C#编程实现,另外我也想知道它的机理,是否如 lmdhit(封情) 所说