Ping IP或HOSTNAME问题,总是返回:TTL已过期! [英] Ping IP or HOSTNAME problem , always returns : TTL expired !

查看:345
本文介绍了Ping IP或HOSTNAME问题,总是返回:TTL已过期!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ping ip或hostnames的问题...问题是总是收到状态:TTL过期即使主机无法访问,不存在或其他...



代码是这样的:



Problem with pinging ip or hostnames... The problem is that always receive Status : TTL Expire even when host is not reachable,doesnt exist, or other ...

code is this :

PingReply Reply = await pingo.SendPingAsync(text_ip.Text, 4000, buffer, options);
            Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
            switch (Reply.Status)
            {
                case IPStatus.Success:

                    Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;

                case IPStatus.TimedOut:

                    Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;

                case IPStatus.TimeExceeded:

                    Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;

                case IPStatus.DestinationHostUnreachable:


                   Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;

                case IPStatus.DestinationNetworkUnreachable:

                    Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;

                case IPStatus.DestinationUnreachable:

                    Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                    break;
            }







例如添加未分配给任何设备的IP地址时并且没有返回:目标主机无法访问或其他东西,但只有ttl过期了!



什么错了?



我尝试了什么:



尝试将ttl设置为64跳,128和许多其他选项,但是同样的事情。我正在尝试ping一个与无线连接的调制解调器,默认网关地址是:192.168.1.1。当ping这一切都没问题,但是例如如果ping一个没有分配的ip,例如192.168.1.123它总是返回ttl过期,它应该是:Destination Host Unreachable。感谢您的时间 。在opossite adb shell ping 192.168.1.123返回:目标主机无法访问




For example when add a ip adress that is not assigned to any device and is doesnt return : Destination Host Unreachable or something else , but only ttl expired !

Whats wrong ?

What I have tried:

Tried to set ttl to 64 hops , 128 , and many other options, but is the same thing. i'm trying to ping a modem that im connected with Wireless , the default gateway adress is : 192.168.1.1 . When ping this everything is ok , but for example if ping a ip that is not assigned somewhere for example 192.168.1.123 it always return ttl expired , when it should be : Destination Host Unreachable . Thank you for your time . In opossite adb shell ping 192.168.1.123 returns : Destination host unreachable

推荐答案

您正在尝试ping同一网络中的系统。因此,没有涉及的路由器可能会返回目标主机无法访问。除了关注请求之外,没有其他设备对回应请求作出反应,如果不存在,则会发生超时。



使用ADB shell时,ping命令在您的Android设备上执行,该设备可能位于不同的子网(WLAN)中。然后涉及路由器(将包从WLAN转发到LAN)并可能生成无法访问的消息。





我忽略了问题是返回TTL而不是超时。



使用Mono时,可以在 mono/Ping.cs at master·mono / mono·GitHub [ ^ ]。

调用系统 ping 命令并检查退出代码:

You are trying to ping a system in the same network. So there is no router involved that might return a Destination Host Unreachable. There is no other device reacting on the echo request besides the adressed one and if that is not present a time out will occur.

When using the ADB shell, the ping command is executed on your Android device which is probably located in a different subnet (WLAN). Then a router is involved (forwarding packages from WLAN to LAN) and may generate an unreachable message.


I overlooked that the problem is that TTL expired is returned instead of a time out.

When using Mono, the used sources can be found at mono/Ping.cs at master · mono/mono · GitHub[^].
That calls the system ping command and checks the exit code:
if (!ping.WaitForExit (timeout) || (ping.HasExited && ping.ExitCode == 2))
    status = IPStatus.TimedOut;
else if (ping.ExitCode == 0)
    status = IPStatus.Success;
else if (ping.ExitCode == 1)
    status = IPStatus.TtlExpired;



因此在没有超时,没有错误或成功时设置TTL过期(退出代码2或0),退出代码为1.

请参阅 ping(8) - Linux手册页 [ ^ ]返回1的案例:


So TTL expired is set when there was no timeout, no error or success (exit code 2 or 0), and the exit code was 1.
See ping(8) - Linux man page[^] for the cases of returning 1:

Quote:

如果ping根本没有收到任何回复数据包,它将以代码1退出。如果是数据包计数和截止时间都是指定的,并且在截止时间到达之前接收到的计数数据包少于它,它也将以代码1退出。在其他错误上它以代码2退出。否则它以代码0退出。这使得它可以使用退出代码来查看主机是否存活。

If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.



因此,返回值1表示没有收到响应(由于各种原因),Mono实现在这种情况下设置TTL过期状态。我希望在这种情况下会返回暂停状态。但似乎没有在这里触发Mono实现的超时检测(例如,因为 ping 命令在它自己的超时之前退出)。



所以有两种可能的解决方案:


So a return value of 1 indicates that no response has been received (for various reasons) and the Mono implementation sets the TTL expired status in this case. I would expect that a time out status would be returned in such cases. But it seems that the timeout detection of the Mono implementation is not triggered here (e.g. because the ping command exits upon on it's own timeout before).

So there are two possible solutions:



  1. 将TTL过期作为主机不活动(但这将忽略忽略真正的TTL已过期检测)
  2. 检查Mono源以查看是否可以降低内部超时值(或者可以增强传递给 ping 命令的值)并发送错误报告

  1. Treat a TTL expired as host not alive (but this will then ignore ignore real TTL expired detections)
  2. Check the Mono sources to see if the internal timeout value can be lowered (or the value passed to the ping command can be enhanced) and send a bug report



[/ EDIT]


[/EDIT]


这篇关于Ping IP或HOSTNAME问题,总是返回:TTL已过期!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆