Skip to content

Instantly share code, notes, and snippets.

@digizeph
Created November 6, 2015 17:58
Show Gist options
  • Select an option

  • Save digizeph/b4f10277f5afa824944a to your computer and use it in GitHub Desktop.

Select an option

Save digizeph/b4f10277f5afa824944a to your computer and use it in GitHub Desktop.
whois api usage example.
package bgpi.utils.whois;
import bgpi.utils.io.Output;
import org.apache.commons.net.whois.WhoisClient;
import java.io.IOException;
/**
* Created by Mingwei on 10/8/15.
* <p>
* Whois utility function using Team Cymru's Whois service.
* <p>
* RIPE response:
* route: 8.0.0.0/8
* origin: AS3356
* descr: LEVEL3 - Level 3 Communications, Inc.,US
* lastupd-frst: 2015-05-12 06:31Z 80.81.192.194@rrc12
* lastupd-last: 2015-10-08 23:37Z 80.81.192.14@rrc12
* seen-at: rrc00,rrc01,rrc03,rrc04,rrc05,rrc06,rrc07,rrc10,rrc11,rrc12,rrc13,rrc14,rrc15
* num-rispeers: 114
* source: RISWHOIS
* <p>
* ... (repeat)
* <p>
* Cymru response:
* AS | IP | BGP Prefix | AS Name
* 15169 | 8.8.8.8 | 8.8.8.0/24 | GOOGLE - Google Inc.,US
*/
public class Whois {
public static void main(String[] args) throws IOException {
WhoisClient whois = new WhoisClient();
whois.connect("whois.cymru.com");
Output.pl(whois.query("-p 8.8.8.8"));
whois.disconnect();
whois.connect("whois.cymru.com");
Output.pl(whois.query("-p 2607:f8b0:400a:806:0:0:0:200e"));
whois.disconnect();
whois.connect("riswhois.ripe.net");
System.out.println(whois.query("8.8.8.0/24"));
whois.disconnect();
whois.connect("riswhois.ripe.net");
System.out.println(whois.query("2607:f8b0:400a:806:0:0:0:200e"));
whois.disconnect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment