Package net.azib.ipscan.core

Examples of net.azib.ipscan.core.ScanningSubject


 
  @Test
  public void testScan() throws UnknownHostException {
    // Some of these tests are run inside of if's to prevent their failing on certain network configurations
    if (!InetAddress.getLocalHost().getCanonicalHostName().equals(InetAddress.getLocalHost().getHostAddress()))
      assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost())));
   
    try {
      InetAddress address = InetAddress.getByName("angryip.org");
      assertEquals("pages.github.com", fetcher.scan(new ScanningSubject(address)));
    }
    catch (UnknownHostException e) { /* ignore - test is running in off-line environment */ }
   
    InetAddress inexistentAddress = InetAddress.getByName("192.168.253.253");
    if (inexistentAddress.getHostName().equals("192.168.253.253"))
      assertNull(fetcher.scan(new ScanningSubject(inexistentAddress)));     
  }
View Full Code Here


public class ICMPSharedPingerTest {
 
  @Test @Ignore("this test works only under root")
  public void testPing() throws Exception {
    Pinger pinger = new ICMPSharedPinger(1000);
    PingResult result = pinger.ping(new ScanningSubject(InetAddress.getLocalHost()), 3);
    assertTrue(result.getAverageTime() >= 0);
    assertTrue(result.getAverageTime() < 50);
    assertTrue(result.getTTL() >= 0);
  }
View Full Code Here

  public void scanWithNoResults() throws Exception {
    // this port is unlikely to be open :-)
    config.portString = "65535";
    fetcher.init();
   
    Object value = fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()));
    assertNull(value);

    fetcher.cleanup();
  }
View Full Code Here

  public void scanInterrupted() throws Exception {
    // these ports are unlikely to be open :-)
    config.portString = "65530-65535";
    fetcher.init();
   
    Object value = fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()));
    assertNull(value);
   
    // reasonably long timeout (if tests fails, we will have to wait this long...)
    config.portTimeout = 3000;
    // but we don't want to wait :-)
    Thread.currentThread().interrupt();
    long testStartTime = System.currentTimeMillis();
    // this host is unlikely to respond
    value = fetcher.scan(new ScanningSubject(InetAddress.getByName("10.255.255.254")));
    assertNull(value);
    assertTrue("port scanning wasn't interrupted", System.currentTimeMillis() - testStartTime < 3000);
   
    // reset interrupted flag
    assertTrue(Thread.interrupted());
View Full Code Here

   
    synchronized (server) {
      server.start();
      server.wait();
    }
    NumericRangeList value = (NumericRangeList) fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()));
    assertEquals(config.portString, value.toString());
   
    fetcher.cleanup();
  }
View Full Code Here

    fetcher = new IPFetcher();
  }
 
  @Test
  public void testScan() throws UnknownHostException {
    assertEquals(InetAddress.getLocalHost().getHostAddress(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost())).toString());
    assertEquals("255.255.255.255", fetcher.scan(new ScanningSubject(InetAddress.getByName("255.255.255.255"))).toString());
  }
View Full Code Here

   
    assertEquals(1234, (int)fileFeeder.next().requestedPortsIterator().next());
    assertFalse(fileFeeder.next().isAnyPortRequested());
    assertFalse(fileFeeder.next().isAnyPortRequested());
   
    ScanningSubject lastSubject = fileFeeder.next();
    assertEquals("1.2.3.5", lastSubject.getAddress().getHostAddress());
    Iterator<Integer> portIterator = lastSubject.requestedPortsIterator();
    assertEquals(80, (int)portIterator.next());
    assertEquals(3128, (int)portIterator.next());
  }
View Full Code Here

    if (this.isReverse) {
      this.currentIP = InetAddressUtils.decrement(prevIP);
    } else {
      this.currentIP = InetAddressUtils.increment(prevIP);
    }
    return new ScanningSubject(prevIP);
  }
View Full Code Here

      while ((fileLine = fileReader.readLine()) != null) {
        Matcher matcher = InetAddressUtils.IP_ADDRESS_REGEX.matcher(fileLine);
        while (matcher.find()) {
          try {
            String address = matcher.group();           
            ScanningSubject subject = foundIPAddresses.get(address);
            if (subject == null)
              subject = new ScanningSubject(InetAddress.getByName(address));
           
            if (!matcher.hitEnd() && fileLine.charAt(matcher.end()) == ':') {
              // see if any valid port is requested
              Matcher portMatcher = PORT_REGEX.matcher(fileLine.substring(matcher.end()+1));
              if (portMatcher.lookingAt()) {
                subject.addRequestedPort(Integer.valueOf(portMatcher.group()));
              }
            }
           
            foundIPAddresses.put(address, subject);
          }
View Full Code Here

  public boolean hasNext() {
    return current < addresses.size();
  }

  public ScanningSubject next() {
    return new ScanningSubject(addresses.get(current++));
  }
View Full Code Here

TOP

Related Classes of net.azib.ipscan.core.ScanningSubject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.