2014-05-09 27 views
6

यह सब एक घंटे पहले और कई दिन पहले काम कर रहा था। लिंक मैं पिंग करने का प्रयास करते है:मुझे पिंगएक्सप्शन क्यों मिल रहा है?

nc = new NetworkConnection(); 
bool bval = nc.PingConnection(satellite_address); 

if (bval) 
{ 
    label19.Visible = true; 
    label19.Text = "Internet Access"; 
} 
else 
{ 
    label19.Visible = true; 
    label19.Text = "No Internet Access"; 
} 

जब यह इस लाइन पर अमल करने की कोशिश कर रहा है::

bool bval = nc.PingConnection(satellite_address); 

यह जा रहा है

Link to ping

यह Form1 में कोड है nc वर्ग:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Net; 
using System.Net.NetworkInformation; 
using System.IO; 
using System.Windows.Forms; 

namespace mws 
{ 
    class NetworkConnection 
    { 
     public NetworkConnection() 
     {  
     } 

     public bool PingConnection(string url) 
     { 
      bool Result = false; 

      using (Ping pp = new Ping()) 
      { 
       byte[] buffer = Encoding.ASCII.GetBytes("samplestring"); 
       int timeout = 120; 

       try 
       { 
        PingReply reply = pp.Send(url, timeout, buffer); 
        if (reply.Status == IPStatus.Success) 
         Result = true; 
       } 
       catch (Exception) 
       { 
        Result = false; 
       } 
      } 
      return Result; 
     } 
    } 
} 

nc कक्षा में जब लाइन करने का प्रयास कर:

PingReply reply = pp.Send(url, timeout, buffer); 

यह कैच ब्लॉक पर कूद रहा है और एक PingException फेंकता है:

एक अपवाद एक पिंग अनुरोध

के दौरान हुई

और उसके बाद फॉर्म 1 में परिणाम यह है कि इंटरनेट एक्सेस नहीं है लेकिन इंटरनेट है और मैं यूआरएल में कोई समस्या नहीं डाल सकता।

यह पूरा अपवाद संदेश है:

System.Net.NetworkInformation.PingException was caught 
    HResult=-2146233079 
    Message=An exception occurred during a Ping request. 
    Source=System 
    StackTrace: 
     at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options) 
     at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer) 
     at mws.NetworkConnection.PingConnection(String url) in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\NetworkConnection.cs:line 33 
    InnerException: System.Net.Sockets.SocketException 
     HResult=-2147467259 
     Message=No such host is known 
     Source=System 
     ErrorCode=11001 
     NativeErrorCode=11001 
     StackTrace: 
      at System.Net.Dns.GetAddrInfo(String name) 
      at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6) 
      at System.Net.Dns.GetHostAddresses(String hostNameOrAddress) 
      at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options) 
     InnerException: 

लाइन 33 है:

PingReply reply = pp.Send(url, timeout, buffer); 

क्या कारण है कि यह अपवाद दिखाई हो सकता है? इससे पहले कि यह कार्यक्रम अब कुछ कार्यक्रमों के लिए काम कर रहा है, यह पहले दिखाई नहीं दे रहा था।

और मुझे इसे कैसे या कैसे संभालना चाहिए?

+0

क्या आप प्रॉक्सी के पीछे हैं? – Yahya

+0

याहा संख्या। मैं पीछे नहीं हूँ – user3596190

+0

लाइन 33 समस्या समस्या समस्या पिंग अनुरोध में है। –

उत्तर

9

आप नहीं कर सकते हैं पिंग क्लास की Send विधि पर एक पूर्ण यूआरएल पास करें। पैरामीटर string hostNameOrAddress

एक स्ट्रिंग जो आईसीएमपी गूंज संदेश के लिए गंतव्य है कंप्यूटर की पहचान करता है। इस पैरामीटर के लिए निर्दिष्ट मान होस्ट नाम या आईपी पते का स्ट्रिंग प्रस्तुति हो सकता है।

तो तुम केवल www.sat24.com में पास या मेजबान 82.94.176.100 (पार्टिशन मौजूद ping www.sat24.com से लिया गया) के आईपी कर सकते हैं।

यदि आप अपनी विधि में एक पूर्ण यूआरएल पास करना चाहते हैं तो आपको अपने यूआरएल से मेजबान को अपने पिंग करने के लिए निकालना होगा। इस मामले के लिए आप उरी कक्षा

Uri uri = new Uri(url); 
PingReply reply = pp.Send(uri.Host, timeout, buffer); 
+0

धन्यवाद। मेरे आईपी पते में टाइपो। एक अवधि के बजाय एक अल्पविराम। स्पॉट करने के लिए मुश्किल है! –

0
PingReply reply = pp.Send(url, timeout, buffer); 

"ऐसा कोई मेजबान जाना जाता है"

मेरे शर्त है कि ऐसी कोई मेजबान जाना जाता है।

आप पिंग चाहिए "www.sat24.com" नहीं "http://www.sat24.com/ ..."

Ping.Send नहीं कहना है यह एक यूआरएल को स्वीकार करता है

public PingReply Send(
    string hostNameOrAddress, 
    int timeout, 
    byte[] buffer 
) 

hostNameOrAddress A String that identifies the computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address. 

http://msdn.microsoft.com/en-us/library/ms144954(v=vs.110).aspx

संबंधित मुद्दे