Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
library(leaflet)
library(tidyverse)
library(httr)
library(rvest)
library(jsonlite)
library(ipapi)
#devtools::install_github("hrbrmstr/ipapi")
#Find geo Containing Key Word
punch_it <- function(dom) {
POST(url = "https://domainpunch.com/tlds/search.php",
query = list(w=dom),
add_headers(
Origin = "https://domainpunch.com",
`User-Agent` = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.29 Safari/537.36",
Referer = "https://domainpunch.com/tlds/search.php",
`X-Requested-With` = "XMLHttpRequest")) -> res
stop_for_status(res)
res <- content(res, as="text", encoding="UTF-8")
res <- jsonlite::fromJSON(res, flatten=FALSE)
if (length(res$table)>0) {
ret <- read_html(res$table) %>% html_table() %>% .[[1]]
as_tibble(ret[-1,-1])
} else {
NULL
}
}
sites <- punch_it("defcon")
sites$Zone <- NULL
sites$Info <- NULL
sites$Length <- NULL
#Do GeoLookup
locations <- mutate(geolocate(sites$Domain))
geo <- cbind(sites, locations)
geo <- subset(geo, status!="fail")
#Build Map:
m <- leaflet(geo) %>% addTiles('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png')
m %>% addMarkers(clusterOptions = markerClusterOptions(), ~lon, ~lat, popup = paste("DNS:", geo$Domain, "<br>",
"IP:", geo$query, "<br>",
"ISP", geo$isp, "<br>",
"ASN:", geo$as ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment