-
-
Save anonymous/36afed57eb2b45e339c5 to your computer and use it in GitHub Desktop.
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 | |
# | |
# check for root | |
# | |
abort("re-run with root priviledges") unless Process::Sys.geteuid.zero? | |
# | |
# create a raw socket | |
# | |
raw_socket = Socket.new(AF_INET, SOCK_RAW, IPPROTO_ICMP) | |
# | |
# bind to specific device | |
# | |
raw_socket.setsockopt(SOL_SOCKET, SO_BINDTODEVICE, "tun0") | |
# | |
# create ICMP echo request | |
# | |
icmp_ereq = [0x08, 0x00, 0x89, 0x98, 0x6e, 0x63, 0x00, 0x04, 0x00].pack('C*') | |
# | |
# create ICMP echo reply | |
# | |
#icmp_erep = [0x00, 0x00, 0x91, 0x98, 0x6e, 0x00, 0x04, 0x00].pack('C*') | |
# | |
# send message | |
# | |
raw_socket.send(icmp_ereq, 0, Socket.sockaddr_in(0, '8.8.8.8')) | |
# | |
# read reply | |
# | |
reply, ai = raw_socket.recvfrom(1024) | |
if reply | |
fqdn = ai.getnameinfo[0] | |
$stdout.puts reply | |
$stdout.puts "Received reply from: #{fqdn}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment