在Python中,有没有办法通过ICMP ping服务器,如果服务器响应则返回TRUE,如果没有响应则返回FALSE?
当我ping一个IP地址时,请求超时和命令返回的目标主机不可达之间有什么区别?
在尝试从python中找出ping(ICMP)的最佳方法时,我遇到了以下问题:
答案通常归结为"使用具有root权限的第三方模块"或"使用系统的ping命令并解析输出".在本机方法中,icmplib和M. Cowles以及J. Diemer的ping.py明确提到了root权限的需要,scapy 手册也是如此.
所以从那个方面来看,原本发送没有特权的ICMP ping似乎是不可能的.系统ping命令确实以某种方式进行管理,但其手册页并未阐明如何操作.另一方面,icmp的手册页似乎表明它是可能的:
Non-privileged ICMP
ICMP sockets can be opened with the SOCK_DGRAM socket type without
requiring root privileges. The synopsis is the following:
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP)
Datagram oriented ICMP sockets offer a subset of the functionality avail-
able to raw ICMP sockets. Only IMCP request messages of the following
types can be sent: ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ.
所以看起来,至少根据icmp,它是允许的.那么为什么所有的python工具都无法做到这一点呢?python工具是否过于笼统,并期望特权套接字上的任何工作都具有特权?是否有可能在C中编写ping函数,可以在没有root权限的情况下ping,并用此扩展python?有没有人这样做过?我只是误解了这个问题吗?
我需要从我的android设备对主机进行icmp ping.我需要测量往返时间.我精通android和java,只是不知道要使用什么库.我该怎么做?是否有可能通过3G,Edge?
根据Stevens(TCP/IP Illustrated),traceroute程序使用增量TTL(1,2,3等)将UDP数据包发送到目标主机,以从ICMP TTL EXPIRED消息中获取中间跃点信息.
" 到达目的地 "条件是ICMP PORT UNREACHABLE消息,因为traceroute寻址一个具有高数字的随机端口(即:不太可能有人在那里听)
所以我的问题是:是否存在技术原因(缺点,RFC等) )使用UDP数据包而不是使用例如ICMP回应请求消息(增加TTL)并使用echo reply answer作为结束条件?
我知道ICMP回应应答可能会被中间的防火墙或其他网络设备过滤掉,但我想这也会发生在UDP数据包上;)
非常感谢
Sergio
您可能知道在没有管理权限的情况下,无法使用Windows套接字创建RAW套接字.问题是,我需要发送ICMP消息,因此我需要RAW套接字.问题:我的程序需要在没有管理权限的情况下运行.
这引出了我的问题,ping工具如何发送没有管理权限的ICMP消息?
我正在进行关于网络的视频讲座,讲师提到ICMP作为传输层协议.但是,谷歌搜索显示各种论坛将其描述为网络层协议.这让我很困惑.有人可以澄清吗?
我正在从一台PC向另一台PC发送UDP数据包.我正在使用Wire Shark观看整个活动.我注意到一段时间内,数据包从一个系统平滑传输到另一个系统.然后突然出现ICMP有错误的数据包'port unreachable'.然后它们会消失一段时间,并且UDP数据包再次平滑传输.然后这些ICMP数据包再次出现相同的"端口无法访问"错误.然后这些ICMP数据包再次消失,依此类推.这将以周期性方式继续.
任何人都可以了解可能是什么原因.

ERROR : TypeError: ord() expected string of length 1, but int found
Run Code Online (Sandbox Code Playgroud)
编译程序时出现此错误.
File "C:\Users\Administrator\Desktop\tracer1.py", line 129, in <module>
get_route("www.google.com")
File "C:\Users\Administrator\Desktop\tracer1.py", line 85, in get_route
d = build_packet()
File "C:\Users\Administrator\Desktop\tracer1.py", line 62, in build_packet
myChecksum = checksum(header + data)
File "C:\Users\Administrator\Desktop\tracer1.py", line 28, in checksum
thisVal = ord(str[count+1]) * 256 + ord(str[count])
**TypeError: ord() expected string of length 1, but int found**
Run Code Online (Sandbox Code Playgroud)
该程序是使用ICMP查找traceroute
from socket import *
import socket
import os
import sys
import struct
import time
import select …Run Code Online (Sandbox Code Playgroud) 作为一项任务,我必须在局域网上找到所有活着的计算机.我正在使用类的isReachable功能InetAddress.但问题是没有任何东西可以显示给我.所以我试图isReachable使用谷歌的IP,但仍然无法访问.
这是代码:
import java.net.*;
public class alive{
public static void main(String args[]){
try{
InetAddress ia = InetAddress.getByAddress(new byte[]{(byte)209, (byte)85, (byte)153, (byte)104});
boolean b = ia.isReachable(10000);
if(b){
System.out.println("Reachable");
}
else{
System.out.println("Unrachable");
}
}catch(Exception e){
System.out.println("Exception: " + e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出是: Unreachable
icmp ×10
ping ×5
networking ×4
python ×3
android ×1
java ×1
python-3.x ×1
sockets ×1
traceroute ×1
udp ×1
windows ×1