Search in sources :

Example 1 with Host

use of com.xebia.vulnmanager.models.nmap.objects.Host in project vulnmanager by xebia-research.

the class HostsParserHelper method getHostsFromDocument.

/**
 * All the hosts are extracted from the NMap report and saved in a list of hosts
 *
 * @param nMapDoc Document of NMap report
 */
List<Host> getHostsFromDocument(Document nMapDoc) {
    NodeList hostList = nMapDoc.getElementsByTagName(NMapConstants.PARSER_LITERAL_HOST);
    List<Host> listConnectedHosts = new ArrayList<>();
    // Todo: Change the for loops to streams
    for (int i = 0; i < hostList.getLength(); i++) {
        Node hostNode = hostList.item(i);
        if (hostNode.getAttributes().getNamedItem(NMapConstants.PARSER_LITERAL_START_TIME) != null) {
            NodeList hostDataList = hostNode.getChildNodes();
            listConnectedHosts.add(parseHostDataFromNodeList(hostDataList));
        }
    }
    return listConnectedHosts;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Host(com.xebia.vulnmanager.models.nmap.objects.Host)

Example 2 with Host

use of com.xebia.vulnmanager.models.nmap.objects.Host in project vulnmanager by xebia-research.

the class HostsParserHelper method parseHostDataFromNodeList.

private Host parseHostDataFromNodeList(NodeList hostDataList) {
    StateDetails stateDetails = null;
    AddressDetails addressDetails = null;
    HostNamesDetails hostNamesDetails = null;
    HostPorts hostPorts = null;
    TimingData timingData = null;
    for (int x = 0; x < hostDataList.getLength(); x++) {
        Node currentHostDetail = hostDataList.item(x);
        NamedNodeMap currentChildAttributes = currentHostDetail.getAttributes();
        String currentNodeName = currentHostDetail.getNodeName();
        switch(currentNodeName) {
            case NMapConstants.PARSER_LITERAL_STATUS:
                stateDetails = getStatusDetails(currentChildAttributes);
                break;
            case NMapConstants.PARSER_LITERAL_ADDRESS:
                addressDetails = getAddressDetails(currentChildAttributes);
                break;
            case NMapConstants.PARSER_LITERAL_HOST_NAMES:
                hostNamesDetails = getHostNamesDetails(currentHostDetail.getChildNodes());
                break;
            case NMapConstants.PARSER_LITERAL_PORTS:
                hostPorts = getPortDetails(currentHostDetail.getChildNodes());
                break;
            case NMapConstants.PARSER_LITERAL_TIMES:
                timingData = getTimingData(currentChildAttributes);
                break;
            default:
                break;
        }
    }
    return new Host(stateDetails, addressDetails, hostNamesDetails, hostPorts, timingData);
}
Also used : HostPorts(com.xebia.vulnmanager.models.nmap.objects.HostPorts) NamedNodeMap(org.w3c.dom.NamedNodeMap) AddressDetails(com.xebia.vulnmanager.models.nmap.objects.AddressDetails) Node(org.w3c.dom.Node) StateDetails(com.xebia.vulnmanager.models.nmap.objects.StateDetails) Host(com.xebia.vulnmanager.models.nmap.objects.Host) HostNamesDetails(com.xebia.vulnmanager.models.nmap.objects.HostNamesDetails) TimingData(com.xebia.vulnmanager.models.nmap.objects.TimingData)

Example 3 with Host

use of com.xebia.vulnmanager.models.nmap.objects.Host in project vulnmanager by xebia-research.

the class NMapParser method getNMapReport.

public NMapReport getNMapReport(Document nMapDoc) {
    ScanDataParserHelper scanDataParserHelper = new ScanDataParserHelper();
    HostsParserHelper hostsParserHelper = new HostsParserHelper();
    NMapGeneralInformation nMapScanData = scanDataParserHelper.getReportData(nMapDoc);
    List<Host> hosts = hostsParserHelper.getHostsFromDocument(nMapDoc);
    return new NMapReport(nMapScanData, hosts);
}
Also used : NMapReport(com.xebia.vulnmanager.models.nmap.objects.NMapReport) NMapGeneralInformation(com.xebia.vulnmanager.models.nmap.objects.NMapGeneralInformation) Host(com.xebia.vulnmanager.models.nmap.objects.Host)

Aggregations

Host (com.xebia.vulnmanager.models.nmap.objects.Host)3 Node (org.w3c.dom.Node)2 AddressDetails (com.xebia.vulnmanager.models.nmap.objects.AddressDetails)1 HostNamesDetails (com.xebia.vulnmanager.models.nmap.objects.HostNamesDetails)1 HostPorts (com.xebia.vulnmanager.models.nmap.objects.HostPorts)1 NMapGeneralInformation (com.xebia.vulnmanager.models.nmap.objects.NMapGeneralInformation)1 NMapReport (com.xebia.vulnmanager.models.nmap.objects.NMapReport)1 StateDetails (com.xebia.vulnmanager.models.nmap.objects.StateDetails)1 TimingData (com.xebia.vulnmanager.models.nmap.objects.TimingData)1 ArrayList (java.util.ArrayList)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 NodeList (org.w3c.dom.NodeList)1