mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
nicer loading code
This commit is contained in:
parent
c4b5b537d2
commit
3a8c409acb
@ -9,17 +9,15 @@ import com.sun.jna.Structure;
|
||||
* JNA binding for iphlpapi.dll for ICMP and ARP support under Windows
|
||||
*/
|
||||
public interface WinIpHlpDll extends Library {
|
||||
public static WinIpHlpDll dll = Loader.load();
|
||||
static class Loader {
|
||||
private static WinIpHlpDll dll;
|
||||
public static WinIpHlpDll load() {
|
||||
if (dll != null) return dll;
|
||||
try {
|
||||
dll = (WinIpHlpDll) Native.loadLibrary("iphlpapi", WinIpHlpDll.class);
|
||||
return (WinIpHlpDll) Native.loadLibrary("iphlpapi", WinIpHlpDll.class);
|
||||
}
|
||||
catch (UnsatisfiedLinkError e) {
|
||||
dll = (WinIpHlpDll) Native.loadLibrary("icmp", WinIpHlpDll.class);
|
||||
return (WinIpHlpDll) Native.loadLibrary("icmp", WinIpHlpDll.class);
|
||||
}
|
||||
return dll;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static java.lang.Thread.currentThread;
|
||||
import static net.azib.ipscan.core.net.WinIpHlpDll.dll;
|
||||
|
||||
/**
|
||||
* Windows-only pinger that uses Microsoft's ICMP.DLL for its job.
|
||||
@ -28,11 +29,9 @@ import static java.lang.Thread.currentThread;
|
||||
*/
|
||||
public class WindowsPinger implements Pinger {
|
||||
private int timeout;
|
||||
private WinIpHlpDll dll;
|
||||
|
||||
public WindowsPinger(int timeout) {
|
||||
this.timeout = timeout;
|
||||
dll = WinIpHlpDll.Loader.load();
|
||||
}
|
||||
|
||||
public PingResult ping(ScanningSubject subject, int count) throws IOException {
|
||||
|
||||
@ -2,16 +2,14 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import net.azib.ipscan.core.net.WinIpHlpDll;
|
||||
import net.azib.ipscan.core.net.WinIpHlpDll.IpAddrByVal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class WinMACFetcher extends MACFetcher {
|
||||
private WinIpHlpDll dll;
|
||||
import static net.azib.ipscan.core.net.WinIpHlpDll.dll;
|
||||
|
||||
public class WinMACFetcher extends MACFetcher {
|
||||
@Override public void init() {
|
||||
dll = WinIpHlpDll.Loader.load();
|
||||
}
|
||||
|
||||
@Override public String resolveMAC(InetAddress address) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user