mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
use adapted timeout instead of fixed pingTimeout
This commit is contained in:
parent
141568bec8
commit
bdfb7a6732
@ -4,7 +4,6 @@
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.config.ScannerConfig;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.util.MDNSResolver;
|
||||
|
||||
@ -42,12 +41,6 @@ public class HostnameFetcher extends AbstractFetcher {
|
||||
|
||||
public static final String ID = "fetcher.hostname";
|
||||
|
||||
private ScannerConfig config;
|
||||
|
||||
public HostnameFetcher(ScannerConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
@ -67,11 +60,11 @@ public class HostnameFetcher extends AbstractFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveWithMulticastDNS(InetAddress ip) {
|
||||
private String resolveWithMulticastDNS(ScanningSubject subject) {
|
||||
try {
|
||||
// TODO: do this only in case of local subnet
|
||||
MDNSResolver resolver = new MDNSResolver(config.pingTimeout);
|
||||
String name = resolver.resolve(ip);
|
||||
MDNSResolver resolver = new MDNSResolver(subject.getAdaptedPortTimeout());
|
||||
String name = resolver.resolve(subject.getAddress());
|
||||
resolver.close();
|
||||
return name;
|
||||
}
|
||||
@ -82,7 +75,7 @@ public class HostnameFetcher extends AbstractFetcher {
|
||||
|
||||
public Object scan(ScanningSubject subject) {
|
||||
String name = resolveWithRegularDNS(subject.getAddress());
|
||||
if (name == null) name = resolveWithMulticastDNS(subject.getAddress());
|
||||
if (name == null) name = resolveWithMulticastDNS(subject);
|
||||
// TODO: incorporate NetBIOS name here as well
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class FetcherRegistryTest {
|
||||
|
||||
ipFetcher = new IPFetcher();
|
||||
pingFetcher = new PingFetcher(null, null);
|
||||
hostnameFetcher = new HostnameFetcher(null);
|
||||
hostnameFetcher = new HostnameFetcher();
|
||||
commentFetcher = new CommentFetcher(null);
|
||||
portsFetcher = new PortsFetcher(null);
|
||||
fetcherRegistry = new FetcherRegistry(new Fetcher[] {ipFetcher, pingFetcher, hostnameFetcher, commentFetcher, portsFetcher}, preferences, null);
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.config.ScannerConfig;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -13,7 +12,6 @@ import java.net.UnknownHostException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* HostnameFetcherTest
|
||||
@ -24,7 +22,7 @@ public class HostnameFetcherTest extends AbstractFetcherTestCase {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
fetcher = new HostnameFetcher(mock(ScannerConfig.class));
|
||||
fetcher = new HostnameFetcher();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user