本文整理汇总了C#中Ping类的典型用法代码示例。如果您正苦于以下问题:C# Ping类的具体用法?C# Ping怎么用?C# Ping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ping类属于命名空间,在下文中一共展示了Ping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: checkConnection
// The state object is necessary for a TimerCallback.
public void checkConnection(object stateObject)
{
Process p = new Process();
Ping pingSender = new Ping ();
p.StartInfo.FileName = "arp";
p.StartInfo.Arguments = "-a";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
string data = "a";
byte[] buffer = Encoding.ASCII.GetBytes (data);
for(int i = 0; i < 25 ; i++){
pingSender.Send ("10.0.0."+i.ToString(),10,buffer);
}
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
string MAC = "xx-xx-xx-xx-xx-xx";
if(output.Contains(MAC)){
SerialPort port = new SerialPort("COM5", 9600);
port.Open();
port.Write("u");
port.Close();
}
else{
SerialPort port = new SerialPort("COM5", 9600);
port.Open();
port.Write("l");
port.Close();
}
}
示例2: Any
public object Any(Ping request)
{
return new PingResponse
{
Result = RedisNative.Ping()
};
}
示例3: SendPingAsync_InvalidArgs
public async Task SendPingAsync_InvalidArgs()
{
IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();
Ping p = new Ping();
// Null address
Assert.Throws<ArgumentNullException>("address", () => { p.SendPingAsync((IPAddress)null); });
Assert.Throws<ArgumentNullException>("hostNameOrAddress", () => { p.SendPingAsync((string)null); });
// Invalid address
Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.Any); });
Assert.Throws<ArgumentException>("address", () => { p.SendPingAsync(IPAddress.IPv6Any); });
// Negative timeout
Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(localIpAddress, -1); });
Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { p.SendPingAsync(TestSettings.LocalHost, -1); });
// Null byte[]
Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(localIpAddress, 0, null); });
Assert.Throws<ArgumentNullException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 0, null); });
// Too large byte[]
Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(localIpAddress, 1, new byte[65501]); });
Assert.Throws<ArgumentException>("buffer", () => { p.SendPingAsync(TestSettings.LocalHost, 1, new byte[65501]); });
}
示例4: update
//-------------------------------------------------------------------------
public void update(float elapsed_tm)
{
if (!mStart) return;
if (mPing != null && mPing.isDone)
{
PingTime = mPing.time;
if (mPing != null)
{
mPing.DestroyPing();
mPing = null;
mPingTm = 5f;
}
}
else if (mPing == null)
{
mPingTm -= elapsed_tm;
if (mPingTm < 0f)
{
mPingTm = 5f;
mPing = new Ping(mIp);
}
}
}
示例5: Any
public object Any(Ping request)
{
return new PingResponse()
{
Timestamp = DateTime.Now
};
}
示例6: Main
public static void Main(string [] args)
{
int pingsc = 0, pingf = 0;
int numb = Convert.ToInt32(args[1]);
Ping ping = new Ping();
PingOptions option = new PingOptions();
option.DontFragment = true;
string message = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdfasdfasdfasfasdfasdfasdfasdfasdfas";
byte [] val = Encoding.ASCII.GetBytes(message);
int timeout = 120;
for(int i = 0; i < numb; i++)
{
PingReply reply = ping.Send(args[0], timeout, val, option);
if(reply.Status == IPStatus.Success)
{
Console.WriteLine("Address {0} " , reply.Address.ToString());
Console.WriteLine("RoundTrip time {0} " ,reply.RoundtripTime);
Console.WriteLine("Time to live {0}", reply.Options.Ttl);
Console.WriteLine("Buffer size {0}", reply.Buffer.Length);
pingsc++;
}
else
{
Console.WriteLine("Ping failed");
pingf++;
}
}
Console.WriteLine("number of Success pings {0}", pingsc);
Console.WriteLine("Number of failed pings {0}", pingf);
}
示例7: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
private static void Main()
{
using (var game = new Ping())
{
game.Run();
}
}
示例8: Main
public static void Main(string[] args)
{
using (Ping ping = new Ping())
{
try
{
PingReply reply = ping.Send("127.0.0.1", 100);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Success - IP Address:{0} Time:{1}ms",
reply.Address, reply.RoundtripTime);
}
else
{
Console.WriteLine(reply.Status);
}
}
catch (Exception ex)
{
Console.WriteLine("Error ({0})", ex.InnerException.Message);
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
示例9: Update
private void Update()
{
if ( this.hostDataIndex != -1 )
{
// Constantly create a new ping and send it off when the old one is returned
if ( this.ping != null )
{
if ( this.ping.isDone )
{
this.latency = this.ping.time;
this.ping = null;
this.UpdateGUI();
}
}
else
{
HostData hostData = MenuNetworking.instance.GetHostData( this.hostDataIndex );
if ( hostData == null )
{
this.hostDataIndex = -1;
}
else
{
this.ping = new Ping( string.Concat( hostData.ip ) );
}
//this.ping = new Ping( string.Concat( this.hostData.ip ) );
}
}
}
示例10: Update
void Update()
{
if (Input.GetButtonDown("Server List"))
{
show = !show;
if (show)
{
MasterServer.ClearHostList();
MasterServer.RequestHostList("OmniDig");
}
}
if (MasterServer.PollHostList().Length > 0)
{
servers = MasterServer.PollHostList();
for(int i=0; i<servers.Length; i++)
{
if (serverPings[i] == null)
{
serverPings[i] = new Ping(servers[i].ip[0]);
}
}
}
if (connect)
{
show = false;
connect = false;
OmniNetwork.Dedicated = false;
Network.Connect(servers[connectSelection]);
}
}
示例11: UpdateServer
public void UpdateServer()
{
//get current server selection
server = (int)slider.value;
//web player ping
ping = new Ping(IPs[server]);
}
示例12: Puck
public Puck(Ping game, Vector2 position)
: base(game)
{
_ping = game;
_size = new Vector2(32f, 32f);
_position = position;
_velocity = new Vector2(5f);
}
示例13: Can_serialize_IMessage_into_typed_Message_Ping
public void Can_serialize_IMessage_into_typed_Message_Ping()
{
var dto = new Ping();
IMessage iMsg = MessageFactory.Create(dto);
var json = iMsg.ToJson();
var typedMessage = json.FromJson<Message<Ping>>();
Assert.That(typedMessage.GetBody(), Is.Not.Null);
}
示例14: Paddle
public Paddle(Ping game, Vector2 position)
: base(game)
{
_ping = game;
_size = new Vector2(24f, 88f);
_position = position;
_velocity = new Vector2(0f);
}
示例15: when_serializing_ping_then_can_roundtrip
public void when_serializing_ping_then_can_roundtrip()
{
var message = new Ping();
var bytes = MessageChannel.Convert(message);
var deserialized = MessageChannel.Convert(bytes) as Ping;
Assert.NotNull(deserialized);
}