knitr::opts_chunk$set(collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE) options(width=60)
Send User Datagram Protocol ('UDP') Probes and Receive Responses
Unfortunately (but understandably) R has no built in connection support for the user datagram protocol ('UDP'). We aim to somewhat fix that with the ability to send a lightweight probe and receive lightweight responses over 'UDP' to a target host/port. Supports Windows, macOS and Linux clients.
The following functions are implemented:
The core probe function:
udp_send_payload
: Send a UDP payload and return the response (if any)Helpers for Ubiquity Discover Protocol probes:
ubnt_discovery_probe
: Send a Ubiquiti Discovery probe to a host with a discovery query payload and receive a response
udpprobe Send UDP payloads and gather responseparse_ubnt_discovery_response
: Parser for Ubiquiti Discovery Protocol responsesHelpers for old, insecure internet services:
udp_daytime
: Send an request for the day/timeudp_echo
: Send an echo request to an echo serverudp_qotd
: Send an request for the QOTDdevtools::install_git("https://git.sr.ht/~hrbrmstr/udpprobe") # or devtools::install_gitlab("hrbrmstr/udpprobe") # or devtools::install_github("hrbrmstr/udpprobe")
library(udpprobe) # current version packageVersion("udpprobe")
What's the IP address of example.com
?
c( 0xaa, 0xaa, # id 0x01, 0x00, # |QR| Opcode |AA|TC|RD|RA| Z | RCODE | 0x00, 0x01, # QDCOUNT num of questions 0x00, 0x00, # ANCOUNT 0 since it's only for answers 0x00, 0x00, # NSCOUNT 0 since it's only for answers 0x00, 0x00, # ARCOUNT 0 sicne it's only for answers 0x07, # start of QNAME beginning with size of "example" 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, # example 0x03, # size of "com" (excluding null terminator) 0x63, 0x6f, 0x6d, 0x00, # "com" with null terminator 0x00, 0x01, # QTYPE ("A" == 1) 0x00, 0x01 # QCLASS (internet == 1) ) -> dns_req (resp <- udp_send_payload("8.8.8.8", 53, dns_req)) paste0(as.integer(tail(resp, 4)), collapse = ".") curl::nslookup("example.com")
# the following just does: # udp_send_payload(Sys.getenv("UBNT_TEST_HOST"), 10001L, c(0x01, 0x00, 0x00, 0x00)) (x <- ubnt_discovery_probe(Sys.getenv("UBNT_TEST_HOST"))) parse_ubnt_discovery_response(x)
cat(udp_echo("91.207.125.246", "the message you want back"), "\n") cat(udp_qotd("119.48.167.199"), "\n") cat(udp_daytime("195.34.89.241"), "\n")
cloc::cloc_pkg_md()
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.