2016-09-08 4 views
0

내 질문은 java를 사용하는 것을 제외하고는 MS Azure - automatically download the latest ip ranges used by MS Azure Datacenters과 비슷합니다.Azure Microsoft Azure Datacenter IP Range 다운로드 Java

java를 사용하여 https://www.microsoft.com/en-us/download/confirmation.aspx?id=41653에서 다운로드 링크를 긁어서 URL에서 다시 다운로드하려고하지만 MS Azure가이를 수행하는 데 더 쉬운 옵션을 제공해야한다고 생각합니다. 누구나 방화벽에서 흰색으로 나열하려면이 기능이 필요합니다.

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(); 
    } 
}