小平Linux内核3.x+的简单ICMP ping实现。要使用它,您需要在 /proc/sys/net/ipv4/ping_group_range 设置允许的组。我在我的logstash ping插件中使用它来执行ping:


require \"ffi\"

module TinyPing

  extend FFI::Library

  ffi_lib '/usr/lib64/libtinyping.so'

  attach_function :init, [:int, :int], :int

  attach_function :ping, [:string], :long_long

  attach_function :deinit, [], :void

end

@ttl = 255

@timeout = 2

raise if TinyPing.init(@ttl, @timeout) != 0