Es hat alles vor einer Stunde und vor vielen Tagen funktioniert. Der Link i ping versuchen ist:Warum bekomme ich PingException?
Dies ist der Code in form1 ist:
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";
}
Wenn es versucht, diese Zeile auszuführen:
bool bval = nc.PingConnection(satellite_address);
Es wird die nc
Klasse:
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;
}
}
}
in der NC-Klasse, wenn die Linie zu tun versuchen:
PingReply reply = pp.Send(url, timeout, buffer);
Es ist an den catch-Block springen und wirft einen PingException:
Eine Ausnahme während einer Ping-Anforderung aufgetreten
Und dann in Form1 das Ergebnis es ist, dass es keinen Internetzugang gibt, aber es gibt Internet und ich kann auf die URL keine Probleme surfen.
Dies ist die komplette Ausnahmemeldung:
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:
Linie 33:
PingReply reply = pp.Send(url, timeout, buffer);
Was könnte der Grund sein, dass diese Ausnahme auftauchen? Es ist nicht aufgetaucht, bevor mein Programm für einige Jahre funktioniert.
Und was oder wie soll ich damit umgehen?
Sind Sie hinter einem Proxy? – Yahya
Yaha nein. Ich bin nicht hinter mir. – user3596190
Zeile 33 ist kein Problem, Problem ist in Ping-Anfrage. –