

{"id":2028,"date":"2013-02-07T23:22:18","date_gmt":"2013-02-08T04:22:18","guid":{"rendered":"http:\/\/rud.is\/b\/?p=2028"},"modified":"2017-04-02T22:51:38","modified_gmt":"2017-04-03T03:51:38","slug":"retrieve-ip-asn-bgp-peer-info-with-r","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/","title":{"rendered":"Retrieve IP ASN &#038; BGP Peer Info With R"},"content":{"rendered":"<p>This is part of a larger project I&#8217;m working on, but it&#8217;s useful enough to share (github version coming soon).<\/p>\n<p>The fine folks at @TeamCymru have a <a href=\"http:\/\/www.team-cymru.org\/IP-ASN-mapping.html\">great service<\/a> to map IP addresses to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Autonomous_System_(Internet)\">ASN\/BGP<\/a> information en masse.<\/p>\n<p>There are libraries for Python, Perl and other languages but none for R (that I could find). So, I threw together a quick set of functions to interface to @TeamCymru&#8217;s service. Unlike many other modern services, this one isn&#8217;t <code>XML<\/code> or <code>JSON<\/code> over a <code>REST<\/code>ful interface, so the code uses a <code>socketConnection()<\/code> over the standard <code>WHOIS<\/code> TCP port to post and retrieve simple text lists.<\/p>\n<pre lang=\"rsplus\">#\r\n# bulkorigin.R - perform bulk IP to ASN mapping via Team Cymru whois service\r\n#\r\n# Author: @hrbrmstr\r\n# Version: 0.1\r\n# Date: 2013-02-07\r\n#\r\n# Copyright 2013 Bob Rudis\r\n# \r\n# Permission is hereby granted, free of charge, to any person obtaining\r\n# a copy of this software and associated documentation files (the\r\n# \"Software\"), to deal in the Software without restriction, including\r\n# without limitation the rights to use, copy, modify, merge, publish,\r\n# distribute, sublicense, and\/or sell copies of the Software, and to\r\n# permit persons to whom the Software is furnished to do so, subject to\r\n# the following conditions:\r\n#   \r\n# The above copyright notice and this permission notice shall be\r\n# included in all copies or substantial portions of the Software.\r\n# \r\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\n# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\n# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\n# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r\n# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\n# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r\n# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.#\r\n\r\nlibrary(plyr)\r\n\r\n# short function to trim leading\/trailing whitespace\r\ntrim <- function (x) gsub(\"^\\\\s+|\\\\s+$\", \"\", x)\r\n\r\nBulkOrigin <- function(ip.list,host=\"v4.whois.cymru.com\",port=43) {\r\n  \r\n  # Retrieves BGP Origin ASN info for a list of IP addresses\r\n  #\r\n  # NOTE: IPv4 version\r\n  #\r\n  # NOTE: The Team Cymru's service is NOT a GeoIP service!\r\n  # Do not use this function for that as your results will not\r\n  # be accurate.\r\n  #\r\n  # Args:\r\n  #   ip.list : character vector of IP addresses\r\n  #   host: which server to hit for lookup (defaults to Team Cymru's server)\r\n  #   post: TCP port to use (defaults to 43)\r\n  #\r\n  # Returns:\r\n  #   data frame of BGP Origin ASN lookup results\r\n  \r\n  \r\n  # setup query\r\n  cmd = \"begin\\nverbose\\n\" \r\n  ips = paste(unlist(ip.list), collapse=\"\\n\")\r\n  cmd = sprintf(\"%s%s\\nend\\n\",cmd,ips)\r\n  \r\n  # setup connection and post query\r\n  con = socketConnection(host=host,port=port,blocking=TRUE,open=\"r+\")  \r\n  cat(cmd,file=con)\r\n  response = readLines(con)\r\n  close(con)\r\n\r\n  # trim header, split fields and convert results\r\n  response = response[2:length(response)]\r\n  response = lapply(response,function(n) {\r\n    sapply(strsplit(n,\"|\",fixed=TRUE),trim)\r\n  })  \r\n  response = adply(response,c(1))\r\n  response = response[,2:length(response)]\r\n  names(response) = c(\"AS\",\"IP\",\"BGP.Prefix\",\"CC\",\"Registry\",\"Allocated\",\"AS.Name\")\r\n  \r\n  return(response)\r\n  \r\n}\r\n\r\nBulkPeer <- function(ip.list,host=\"v4-peer.whois.cymru.com\",port=43) {\r\n  \r\n  # Retrieves BGP Peer ASN info for a list of IP addresses\r\n  #\r\n  # NOTE: IPv4 version\r\n  #\r\n  # NOTE: The Team Cymru's service is NOT a GeoIP service!\r\n  # Do not use this function for that as your results will not\r\n  # be accurate.\r\n  #\r\n  # Args:\r\n  #   ip.list : character vector of IP addresses\r\n  #   host: which server to hit for lookup (defaults to Team Cymru's server)\r\n  #   post: TCP port to use (defaults to 43)\r\n  #\r\n  # Returns:\r\n  #   data frame of BGP Peer ASN lookup results\r\n  \r\n  \r\n  # setup query\r\n  cmd = \"begin\\nverbose\\n\" \r\n  ips = paste(unlist(ip.list), collapse=\"\\n\")\r\n  cmd = sprintf(\"%s%s\\nend\\n\",cmd,ips)\r\n  \r\n  # setup connection and post query\r\n  con = socketConnection(host=host,port=port,blocking=TRUE,open=\"r+\")  \r\n  cat(cmd,file=con)\r\n  response = readLines(con)\r\n  close(con)\r\n  \r\n  # trim header, split fields and convert results\r\n  response = response[2:length(response)]\r\n  response = lapply(response,function(n) {\r\n    sapply(strsplit(n,\"|\",fixed=TRUE),trim)\r\n  })  \r\n  response = adply(response,c(1))\r\n  response = response[,2:length(response)]\r\n  names(response) = c(\"Peer.AS\",\"IP\",\"BGP.Prefix\",\"CC\",\"Registry\",\"Allocated\",\"Peer.AS.Name\")\r\n  return(response)\r\n  \r\n}<\/pre>\n<p>Take a list of IPs, make an IP connection, formulate a bulk query and convert the results. Here's a small script to test it:<\/p>\n<pre lang=\"rsplus\">ips = c(\"100.43.81.11\",\"100.43.81.7\")\r\norigin = BulkOrigin(ips)\r\nstr(origin)\r\npeers = BulkPeer(ips)\r\nstr(peers)<\/pre>\n<p>That code outputs:<\/p>\n<pre lang=\"rsplus\">'data.frame':\t2 obs. of  7 variables:\r\n $ AS        : chr  \"13238\" \"13238\"\r\n $ IP        : chr  \"100.43.81.11\" \"100.43.81.7\"\r\n $ BGP.Prefix: chr  \"100.43.64.0\/19\" \"100.43.64.0\/19\"\r\n $ CC        : chr  \"US\" \"US\"\r\n $ Registry  : chr  \"arin\" \"arin\"\r\n $ Allocated : chr  \"2011-12-06\" \"2011-12-06\"\r\n $ AS.Name   : chr  \"YANDEX Yandex LLC\" \"YANDEX Yandex LLC\"<\/pre>\n<p>and<\/p>\n<pre lang=\"rsplus\">'data.frame':\t8 obs. of  7 variables:\r\n $ Peer.AS     : chr  \"174\" \"3257\" \"9002\" \"10310\" ...\r\n $ IP          : chr  \"100.43.81.11\" \"100.43.81.11\" \"100.43.81.11\" \"100.43.81.11\" ...\r\n $ BGP.Prefix  : chr  \"100.43.64.0\/19\" \"100.43.64.0\/19\" \"100.43.64.0\/19\" \"100.43.64.0\/19\" ...\r\n $ CC          : chr  \"US\" \"US\" \"US\" \"US\" ...\r\n $ Registry    : chr  \"arin\" \"arin\" \"arin\" \"arin\" ...\r\n $ Allocated   : chr  \"2011-12-06\" \"2011-12-06\" \"2011-12-06\" \"2011-12-06\" ...\r\n $ Peer.AS.Name: chr  \"COGENT Cogent\/PSI\" \"TINET-BACKBONE Tinet SpA\" \"RETN-AS ReTN.net Autonomous System\" \"YAHOO-1 - Yahoo!\" ...<\/pre>\n<p>respectively for each <code>str()<\/code>.<\/p>\n<p>Nothing super-sexy, but it's part of a mission I'm on to make IP addresses \"first class citizens\" in R. I'm starting with building some smaller functions that accumulate IP metadata and will ultimately collect them all into a compact R library.<\/p>\n<p>In the interim, I thought these two routines might be useful to some folks.<\/p>\n<p>With just these two functions, you can use various graphing libraries to get a picture of the network connectivity. Here's a small sample to get you started:<\/p>\n<pre lang=\"rsplus\">library(igraph)\r\n\r\nips = c(\"100.43.81.11\")\r\norigin = BulkOrigin(ips)\r\npeers = BulkPeer(ips)\r\n\r\ng = graph.empty() + vertices(c(ips, peers$Peer.AS, origin$AS),size=30)\r\nV(g)$label = c(ips, peers$Peer.AS, origin$AS)\r\ne = lapply(peers$Peer.AS,function(x) {\r\n  c(origin$AS,x)\r\n})\r\ng = g + edges(unlist(e))\r\ng = g + edge(ips, origin$AS)\r\ng$layout = layout.circle\r\nplot(g)<\/pre>\n<p><center><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2043\" data-permalink=\"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/asn\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?fit=372%2C366&amp;ssl=1\" data-orig-size=\"372,366\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"asn\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?fit=372%2C366&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?resize=372%2C366&#038;ssl=1\" alt=\"asn\" width=\"372\" height=\"366\" class=\"aligncenter size-full wp-image-2043\" srcset=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?w=372&amp;ssl=1 372w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?resize=150%2C147&amp;ssl=1 150w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?resize=300%2C295&amp;ssl=1 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/center><\/p>\n<p>If you know of any other R libraries or code that provide functions that operate on IP addresses or interface to services that provide IP address metadata, please drop a note in the comments or ping me on Twitter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is part of a larger project I&#8217;m working on, but it&#8217;s useful enough to share (github version coming soon). The fine folks at @TeamCymru have a great service to map IP addresses to ASN\/BGP information en masse. There are libraries for Python, Perl and other languages but none for R (that I could find). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[63,7,91],"tags":[684],"class_list":["post-2028","post","type-post","status-publish","format-standard","hentry","category-development","category-programming","category-r","tag-netintel"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Retrieve IP ASN &amp; BGP Peer Info With R - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Retrieve IP ASN &amp; BGP Peer Info With R - rud.is\" \/>\n<meta property=\"og:description\" content=\"This is part of a larger project I&#8217;m working on, but it&#8217;s useful enough to share (github version coming soon). The fine folks at @TeamCymru have a great service to map IP addresses to ASN\/BGP information en masse. There are libraries for Python, Perl and other languages but none for R (that I could find). [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-08T04:22:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-03T03:51:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Retrieve IP ASN &#038; BGP Peer Info With R\",\"datePublished\":\"2013-02-08T04:22:18+00:00\",\"dateModified\":\"2017-04-03T03:51:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/\"},\"wordCount\":269,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/asn.png\",\"keywords\":[\"netintel\"],\"articleSection\":[\"Development\",\"Programming\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/\",\"name\":\"Retrieve IP ASN & BGP Peer Info With R - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/asn.png\",\"datePublished\":\"2013-02-08T04:22:18+00:00\",\"dateModified\":\"2017-04-03T03:51:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/asn.png?fit=372%2C366&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/asn.png?fit=372%2C366&ssl=1\",\"width\":372,\"height\":366},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2013\\\/02\\\/07\\\/retrieve-ip-asn-bgp-peer-info-with-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Retrieve IP ASN &#038; BGP Peer Info With R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Retrieve IP ASN & BGP Peer Info With R - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/","og_locale":"en_US","og_type":"article","og_title":"Retrieve IP ASN & BGP Peer Info With R - rud.is","og_description":"This is part of a larger project I&#8217;m working on, but it&#8217;s useful enough to share (github version coming soon). The fine folks at @TeamCymru have a great service to map IP addresses to ASN\/BGP information en masse. There are libraries for Python, Perl and other languages but none for R (that I could find). [&hellip;]","og_url":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/","og_site_name":"rud.is","article_published_time":"2013-02-08T04:22:18+00:00","article_modified_time":"2017-04-03T03:51:38+00:00","og_image":[{"url":"https:\/\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png","type":"","width":"","height":""}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Retrieve IP ASN &#038; BGP Peer Info With R","datePublished":"2013-02-08T04:22:18+00:00","dateModified":"2017-04-03T03:51:38+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/"},"wordCount":269,"commentCount":1,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png","keywords":["netintel"],"articleSection":["Development","Programming","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/","url":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/","name":"Retrieve IP ASN & BGP Peer Info With R - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png","datePublished":"2013-02-08T04:22:18+00:00","dateModified":"2017-04-03T03:51:38+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?fit=372%2C366&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/02\/asn.png?fit=372%2C366&ssl=1","width":372,"height":366},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2013\/02\/07\/retrieve-ip-asn-bgp-peer-info-with-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Retrieve IP ASN &#038; BGP Peer Info With R"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p23idr-wI","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2123,"url":"https:\/\/rud.is\/b\/2013\/02\/20\/rnetintel-cross-check-apt-1s-ip-list-with-alienvault-reputation-db-some-graphsanalysis\/","url_meta":{"origin":2028,"position":0},"title":"R\/netintel : Cross-check APT-1&#8217;s IP list with AlienVault Reputation DB (+ some graphs\/analysis)","author":"hrbrmstr","date":"2013-02-20","format":false,"excerpt":"Here's a quick example of couple additional ways to use the netintel R package I've been tinkering with. This could easily be done on the command line with other tools, but if you're already doing scripting\/analysis with R, this provides a quick way to tell if a list of IPs\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12127,"url":"https:\/\/rud.is\/b\/2019\/04\/07\/a-limited-but-functional-couchbase-free-text-search-or-how-i-abused-couchbase-r-to-perform-bulk-ip-whois-full-text-searches-a-cobblers-tale\/","url_meta":{"origin":2028,"position":1},"title":"A Limited-but-Functional Couchbase Free Text Search &#038; Retrieval Un-package; or, &#8220;How I Abused Couchbase &#038; R to Perform Bulk IP Whois Full-text Searches&#8221; (a Cobbler&#8217;s Tale)","author":"hrbrmstr","date":"2019-04-07","format":false,"excerpt":"Researching \"the internet\" (i.e. $DAYJOB) means having to deal with a ton of \"unique\" (I'm being kind) data formats. This is ultimately a tale of how I performed full-text searches across one of them. It all started off innocently enough. This past week I need to be able to do\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3298,"url":"https:\/\/rud.is\/b\/2015\/03\/09\/new-r-package-ipapi-ipdomain-geolocation\/","url_meta":{"origin":2028,"position":2},"title":"New R Package &#8211; ipapi (IP\/Domain Geolocation)","author":"hrbrmstr","date":"2015-03-09","format":false,"excerpt":"I noticed that the @rOpenSci folks had an interface to [ip-api.com](http:\/\/ip-api.com\/) on their [ToDo](https:\/\/github.com\/ropensci\/webservices\/wiki\/ToDo) list so I whipped up a small R package to fill said gap. Their IP Geolocation API will take an IPv4, IPv6 or FQDN and kick back a ASN, lat\/lon, address and more. The [ipapi package](https:\/\/github.com\/hrbrmstr\/ipapi)\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2969,"url":"https:\/\/rud.is\/b\/2014\/04\/25\/moving-from-system-calls-to-rcpp-interfaces\/","url_meta":{"origin":2028,"position":3},"title":"Moving From system() calls to Rcpp Interfaces","author":"hrbrmstr","date":"2014-04-25","format":false,"excerpt":"Over on the [Data Driven Security Blog](http:\/\/datadrivensecurity.info\/blog\/posts\/2014\/Apr\/making-better-dns-txt-record-lookups-with-rcpp\/) there's a post on how to use `Rcpp` to interface with an external library (in this case `ldns` for DNS lookups). It builds on [another post](http:\/\/datadrivensecurity.info\/blog\/posts\/2014\/Apr\/firewall-busting-asn-lookups\/) which uses `system()` to make a call to `dig` to lookup DNS `TXT` records. The core code\u2026","rel":"","context":"In &quot;Information Security&quot;","block_context":{"text":"Information Security","link":"https:\/\/rud.is\/b\/category\/information-security\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2068,"url":"https:\/\/rud.is\/b\/2013\/02\/08\/visualizing-malicious-clusters-outliers\/","url_meta":{"origin":2028,"position":4},"title":"Visualizing Malicious Clusters &#038; Outliers","author":"hrbrmstr","date":"2013-02-08","format":false,"excerpt":"So, I've had some quick, consecutive blog posts around this R package I'm working on, and this one is more of an answer to my own, self-identified question of \"so what?\". As I was working on an importer for AlienValut's IP reputation database, I thought it might be interesting to\u2026","rel":"","context":"In &quot;Data Analysis&quot;","block_context":{"text":"Data Analysis","link":"https:\/\/rud.is\/b\/category\/data-analysis-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2046,"url":"https:\/\/rud.is\/b\/2013\/02\/08\/extended-simple-example-asn-graph-visualization-example-r-to-d3\/","url_meta":{"origin":2028,"position":5},"title":"Extended (Simple) ASN Graph Visualization Example [R to D3]","author":"hrbrmstr","date":"2013-02-08","format":false,"excerpt":"The small igraph visualization in the previous post shows the basics of what you can do with the BulkOrigin & BulkPeer functions, and I thought a larger example with some basic D3 tossed in might be even more useful. Assuming you have the previous functions in your environment, the following\u2026","rel":"","context":"In &quot;d3&quot;","block_context":{"text":"d3","link":"https:\/\/rud.is\/b\/category\/d3\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/2028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=2028"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/2028\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=2028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=2028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=2028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}