2016-09-08 11 views
0

私の質問はMS Azure - automatically download the latest ip ranges used by MS Azure Datacentersに似ていますが、私はそれを行うためにjavaを使用しようとしています。Azure Microsoft Azure Datacenter IP範囲ダウンロード

私は、javaを使用してhttps://www.microsoft.com/en-us/download/confirmation.aspx?id=41653からダウンロードリンクを掻き出し、URLから再度ダウンロードしますが、MS Azureはこれを行うためのいくつかのAPIまたはより簡単なオプションを提供する必要があります。誰もがファイアウォールのホワイトリストに必要です。

Javaでこれを行う方が良い方は、教えてください。

おかげで、

答えて

0

は一緒にdownloadurlを通じてscrapeing後にIPアドレスを抽出するために、粗コードを入れています。 Azureが将来ダウンロードURLの何かを変更した場合、動作しない可能性があります。

private static final String baseURI = "https://www.microsoft.com/en-us/download/confirmation.aspx?id=41653"; 
private static final String downloadURI_Part = "https://download.microsoft.com"; 
private static final String HREF = "href"; 

public static void main(String[] args) { 
    new DownloadXML().parse(); 
} 

public void parse() { 
    try { 
     URL url = new URL(baseURI); 
     String downloadURL = ""; 
     org.jsoup.nodes.Document doc1 = Jsoup.connect(url.toString()).get(); 
     Elements newsHeadlines = doc1.select("a"); 
     for (org.jsoup.nodes.Element element : newsHeadlines) { 
      if (element.hasAttr(HREF) && element.getElementsByAttribute(HREF).attr(HREF) 
        .contains(downloadURI_Part)) { 
       downloadURL = element.getElementsByAttribute(HREF).attr(HREF); 
       System.out.println(element.getElementsByAttribute(HREF).attr(HREF)); 
      } 
     } 
     System.out.println(downloadURL); 
     URL url1 = new URL(downloadURL); 
     DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 
     Document doc = dBuilder.parse(url1.openStream()); 
     doc.getDocumentElement().normalize(); 
     NodeList nRegionList = doc.getElementsByTagName("Region"); 
     System.out.println("----------------------------"); 

     for (int nRegionCount = 0; nRegionCount < nRegionList.getLength(); nRegionCount++) { 
      Node nRegionNode = nRegionList.item(nRegionCount); 
      System.out.println("\nCurrent Element :" + nRegionNode.getNodeName()); 
      if (nRegionNode.getNodeType() == Node.ELEMENT_NODE) { 
       Element eElement = (Element) nRegionNode; 
       System.out.println("Region name: " + eElement.getAttribute("Name")); 
       NodeList nIPRangeList = eElement.getChildNodes(); 
       for (int iprangecnt = 0; iprangecnt < nIPRangeList.getLength(); iprangecnt++) { 
        Node nIPRNode = nIPRangeList.item(iprangecnt); 
        if (nIPRNode.hasAttributes()) { 
         // get attributes names and values 
         NamedNodeMap nodeMap = nIPRNode.getAttributes(); 
         for (int i = 0; i < nodeMap.getLength(); i++) { 
          Node node = nodeMap.item(i); 
          System.out.println("attr name : " + node.getNodeName()); 
          System.out.println("attr value : " + node.getNodeValue()); 
         } 
        } 
       } 
      } 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
関連する問題