Created
May 15, 2016 15:21
-
-
Save gr33n7007h/cf6d44347046f193b7620c1a9887aef9 to your computer and use it in GitHub Desktop.
ping, ping, ping, ping, ping, ping, ping && ping!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
include Socket::Constants | |
begin | |
sock = Socket.new AF_INET, SOCK_RAW, IPPROTO_ICMP | |
rescue Errno::EPERM | |
$stderr.puts "[!] Run with root privileges." | |
exit 1 | |
end | |
iface = Socket.getifaddrs.select { |i| i.addr.ipv4? && i.broadaddr }.first.name | |
sock.setsockopt SOL_SOCKET, SO_BINDTODEVICE, iface | |
data = [0x08, 0x00, 0x89, 0x98, 0x6e, 0x63, 0x00, 0x04, 0x00].pack 'C*' | |
sock.send data, 0, Socket.sockaddr_in(0, '8.8.8.8') | |
r = Socket.select [sock], [], [], 1 | |
if r.first | |
reply = sock.recv sock.nread | |
peer_addr = reply.byteslice(12,4).unpack('C*') * '.' | |
puts "Received (icmp) message from #{peer_addr}\n\tRAW: #{reply}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment