File: ping.rb

package info (click to toggle)
ruby-packetfu 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,520 kB
  • sloc: ruby: 8,344; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Usage:
# rvmsudo ruby examples/ping.rb 8.8.8.8

# Path setting slight of hand:
$: << File.expand_path("../../lib", __FILE__)

require 'packetfu'

ip = ARGV[0].chomp

config = PacketFu::Utils.whoami?()

icmp_packet = PacketFu::ICMPPacket.new(:config => config)
icmp_packet.ip_daddr = ip
icmp_packet.payload = "I'm sending ICMP packets using PacketFu!!!"
icmp_packet.icmp_type = 8
icmp_packet.recalc

capture_thread = Thread.new do
  begin
    Timeout::timeout(3) {
      cap = PacketFu::Capture.new(:iface => config[:iface], :start => true)
      cap.stream.each do |p|
        pkt = PacketFu::Packet.parse p
        next unless pkt.is_icmp?
        if pkt.ip_saddr == ip and pkt.icmp_type == 0
          puts "Got ICMP echo reply from #{ip}"
          break
        end
      end
    }
  rescue Timeout::Error
    puts "ICMP echo request timed out"
  end
end

puts "Sending ICMP echo request to #{ip}"
icmp_packet.to_w

capture_thread.join