Я хочу запустить в своем коде функцию, которая проверяет, находится ли устройство в сети, а также, если TTL меньше, чем 250
но я не нашел где посмотреть TTL
Код:
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1500;
PingReply reply = p.Send(IP,timeout,buffer);
if (reply.Status == IPStatus.Success)
{
time = DateTime.Now.ToString();
Online.Add(IP)
}
Какой вариант увидеть TTL?





Это на удивление необычное занятие, когда вы начинаете программировать, но первое, на что вам следует обратить внимание, когда вы хотите что-то узнать, - это документация.
Метод Ping.Send (IPAddress, Int32, Byte [], PingOptions)
Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress and receive a corresponding ICMP echo reply message from that computer. This overload allows you to specify a time-out value for the operation and control fragmentation and Time-to-Live values for the ICMP echo message packet.
Характеристики
Ttl Gets or sets the number of routing nodes that can forward the Ping data before it is discarded.
Gets or sets the number of routing nodes that can forward the Ping data before it is discarded.
Remarks
As gateways and routers transmit packets through a network, they decrement the current Time-to-Live (TTL) value found in the packet header. If the TTL value reaches zero, the packet is deemed undeliverable and is discarded. This option is useful if you want to test the number of routers and gateways used to transmit the data.
Пример
public static string PingHost(string host)
{
//string to hold our return messge
string returnMessage = string.Empty;
//IPAddress instance for holding the returned host
IPAddress address = GetIpFromHost(ref host);
//set the ping options, TTL 128
PingOptions pingOptions = new PingOptions(128, true);
//create a new ping instance
Ping ping = new Ping();
//32 byte buffer (create empty)
byte[] buffer = new byte[32];
//set the ping options, TTL 128
PingOptions pingOptions = new PingOptions(128, true);
PingReply pingReply = ping.Send(address, 1000, buffer, pingOptions);
if (!(pingReply == null))
{
switch (pingReply.Status)
{
case IPStatus.Success:
returnMessage = string.Format("Reply from {0}: bytes = {1} time = {2}ms TTL = {3}",
pingReply.Address,
pingReply.Buffer.Length,
pingReply.RoundtripTime,
pingReply.Options.Ttl);
break;
case IPStatus.TimedOut:
returnMessage = "Connection has timed out...";
break;
default:
returnMessage = string.Format("Ping failed: {0}", pingReply.Status.ToString());
break;
}
}
else
returnMessage = "Connection failed for an unknown reason...";
...
эта строка ---> PingOptions pingOptions = new PingOptions (128, true); что это значит? что макс 128?
reply.Options.Ttl?