├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── no-response.yml └── workflows │ └── build.yml ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyleSettings.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── dictionaries │ └── anton.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── runConfigurations │ ├── Main.xml │ └── Unit_tests.xml └── vcs.xml ├── CHANGELOG ├── LICENSE ├── Makefile ├── README.md ├── TODO.md ├── build-native-image.sh ├── build.gradle ├── config └── logging.properties ├── ext ├── deb-bundle │ ├── DEBIAN │ │ ├── control │ │ └── copyright │ └── usr │ │ ├── bin │ │ └── ipscan │ │ └── share │ │ ├── applications │ │ └── ipscan.desktop │ │ ├── doc │ │ └── ipscan │ │ │ └── copyright │ │ └── metainfo │ │ └── ipscan.appdata.xml ├── jna.pro ├── mac-bundle │ └── Angry IP Scanner.app │ │ └── Contents │ │ ├── Info.plist │ │ ├── MacOS │ │ └── ipscan │ │ └── Resources │ │ └── ipscan.icns ├── rpmbuild │ └── SPECS │ │ └── ipscan.spec ├── swt.pro ├── win-installer │ ├── .gitignore │ ├── Installer │ │ ├── Installer.nsi │ │ └── InstallerGraphics │ │ │ ├── header-r.bmp │ │ │ ├── header-uninstall-r.bmp │ │ │ ├── header-uninstall.bmp │ │ │ ├── header.bmp │ │ │ ├── installer.ico │ │ │ ├── uninstaller.ico │ │ │ ├── welcomefinish-uninstall.bmp │ │ │ └── welcomefinish.bmp │ └── InstallerConfig.nsh └── win-launcher │ ├── .gitignore │ ├── build.cmd │ ├── launcher.c │ ├── launcher.exe │ └── version.rc ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── resources ├── images │ ├── buttons │ │ ├── fetchers.png │ │ ├── fetchers@2x.png │ │ ├── kill.png │ │ ├── kill.svg │ │ ├── kill@2x.png │ │ ├── prefs.png │ │ ├── prefs@2x.png │ │ ├── start.png │ │ ├── start.svg │ │ ├── start@2x.png │ │ ├── stop.png │ │ ├── stop.svg │ │ └── stop@2x.png │ ├── icon.ico │ ├── icon.png │ ├── icon.svg │ ├── icon128.png │ ├── icon2.svg │ ├── icon256.png │ ├── icon32.ico │ ├── icon32.png │ ├── icon48.png │ └── list │ │ ├── alive.png │ │ ├── alive.svg │ │ ├── alive@2x.png │ │ ├── dead.png │ │ ├── dead.svg │ │ ├── dead@2x.png │ │ ├── ports.png │ │ ├── ports.svg │ │ ├── ports@2x.png │ │ ├── unknown.png │ │ ├── unknown.svg │ │ └── unknown@2x.png ├── mac-vendors.txt ├── messages.properties ├── messages_de.properties ├── messages_es.properties ├── messages_et.properties ├── messages_fi.properties ├── messages_fr.properties ├── messages_gr.properties ├── messages_hu.properties ├── messages_it.properties ├── messages_ku.properties ├── messages_lt.properties ├── messages_pt_BR.properties ├── messages_ru.properties ├── messages_tr.properties ├── messages_zh_CN.properties └── messages_zh_TW.properties ├── src └── net │ └── azib │ └── ipscan │ ├── Main.java │ ├── config │ ├── CommandLineProcessor.java │ ├── CommandProcessor.java │ ├── CommentsConfig.java │ ├── ComponentRegistry.java │ ├── Config.java │ ├── ConfigModule.java │ ├── FavoritesConfig.java │ ├── GUIConfig.java │ ├── GUIRegistry.java │ ├── Labels.java │ ├── LoggerFactory.java │ ├── NamedListConfig.java │ ├── OpenersConfig.java │ ├── Platform.java │ ├── ScannerConfig.java │ └── Version.java │ ├── core │ ├── LibraryLoader.java │ ├── Plugin.java │ ├── PluginLoader.java │ ├── PortIterator.java │ ├── Scanner.java │ ├── ScannerDispatcherThread.java │ ├── ScannerDispatcherThreadFactory.java │ ├── ScanningProgressCallback.java │ ├── ScanningResult.java │ ├── ScanningResultCallback.java │ ├── ScanningResultComparator.java │ ├── ScanningResultList.java │ ├── ScanningSubject.java │ ├── UserErrorException.java │ ├── net │ │ ├── ARPPinger.java │ │ ├── CombinedUnprivilegedPinger.java │ │ ├── JavaPinger.java │ │ ├── PingResult.java │ │ ├── Pinger.java │ │ ├── PingerRegistry.java │ │ ├── TCPPinger.java │ │ ├── UDPPinger.java │ │ ├── WinIpHlp.java │ │ ├── WinIpHlpDll.java │ │ ├── WinKernel32.java │ │ └── WindowsPinger.java │ ├── state │ │ ├── ScanningState.java │ │ ├── StateMachine.java │ │ └── StateTransitionListener.java │ └── values │ │ ├── Empty.java │ │ ├── InetAddressHolder.java │ │ ├── IntegerWithUnit.java │ │ ├── NotAvailable.java │ │ ├── NotScanned.java │ │ └── NumericRangeList.java │ ├── di │ ├── InjectException.java │ └── Injector.java │ ├── exporters │ ├── AbstractExporter.java │ ├── CSVExporter.java │ ├── ExportProcessor.java │ ├── Exporter.java │ ├── ExporterException.java │ ├── ExporterRegistry.java │ ├── IPListExporter.java │ ├── SQLExporter.java │ ├── TXTExporter.java │ └── XMLExporter.java │ ├── feeders │ ├── AbstractFeeder.java │ ├── Feeder.java │ ├── FeederCreator.java │ ├── FeederException.java │ ├── FeederRegistry.java │ ├── FileFeeder.java │ ├── RandomFeeder.java │ ├── RangeFeeder.java │ ├── RescanFeeder.java │ └── SmartTextFeeder.java │ ├── fetchers │ ├── AbstractFetcher.java │ ├── CommentFetcher.java │ ├── Fetcher.java │ ├── FetcherException.java │ ├── FetcherPrefs.java │ ├── FetcherRegistry.java │ ├── FetcherRegistryUpdateListener.java │ ├── FilteredPortsFetcher.java │ ├── HTTPProxyFetcher.java │ ├── HTTPSenderFetcher.java │ ├── HostnameFetcher.java │ ├── IPFetcher.java │ ├── LastAliveTimeFetcher.java │ ├── LinuxMACFetcher.java │ ├── MACFetcher.java │ ├── MACVendorFetcher.java │ ├── NetBIOSInfoFetcher.java │ ├── PacketLossFetcher.java │ ├── PingFetcher.java │ ├── PingTTLFetcher.java │ ├── PortTextFetcher.java │ ├── PortsFetcher.java │ ├── UnixMACFetcher.java │ ├── WebDetectFetcher.java │ └── WinMACFetcher.java │ ├── gui │ ├── AboutDialog.java │ ├── AbstractModalDialog.java │ ├── DetailsWindow.java │ ├── EditFavoritesDialog.java │ ├── EditOpenersDialog.java │ ├── GUI.java │ ├── GettingStartedDialog.java │ ├── InfoDialog.java │ ├── InputDialog.java │ ├── MacApplicationMenu.java │ ├── MainMenu.java │ ├── MainWindow.java │ ├── PreferencesDialog.java │ ├── ResultTable.java │ ├── SWTAwareStateMachine.java │ ├── SelectFetchersDialog.java │ ├── Startup.java │ ├── StatisticsDialog.java │ ├── StatusBar.java │ ├── actions │ │ ├── BrowserLauncher.java │ │ ├── ColumnsActions.java │ │ ├── CommandsMenuActions.java │ │ ├── FavoritesMenuActions.java │ │ ├── FeederActions.java │ │ ├── GotoMenuActions.java │ │ ├── HelpMenuActions.java │ │ ├── OpenerLauncher.java │ │ ├── ScanMenuActions.java │ │ ├── StartStopScanningAction.java │ │ ├── TerminalLauncher.java │ │ └── ToolsActions.java │ ├── feeders │ │ ├── AbstractFeederGUI.java │ │ ├── ControlsArea.java │ │ ├── FeederArea.java │ │ ├── FeederGUIRegistry.java │ │ ├── FeederSelectionCombo.java │ │ ├── FileFeederGUI.java │ │ ├── RandomFeederGUI.java │ │ └── RangeFeederGUI.java │ ├── fetchers │ │ ├── MACFetcherPrefs.java │ │ ├── PingFetcherPrefs.java │ │ ├── PortTextFetcherPrefs.java │ │ └── PortsFetcherPrefs.java │ ├── menu │ │ ├── AbstractMenu.java │ │ ├── ColumnsMenu.java │ │ ├── CommandsMenu.java │ │ ├── ExtendableMenu.java │ │ ├── FavoritesMenu.java │ │ ├── GotoMenu.java │ │ ├── HelpMenu.java │ │ ├── OpenersContextMenu.java │ │ ├── OpenersMenu.java │ │ ├── ResultsContextMenu.java │ │ ├── ScanMenu.java │ │ └── ToolsMenu.java │ └── util │ │ └── LayoutHelper.java │ └── util │ ├── GoogleAnalytics.java │ ├── IOUtils.java │ ├── InetAddressUtils.java │ ├── MDNSResolver.java │ ├── NetBIOSResolver.java │ ├── OctetConverter.java │ ├── SequenceIterator.java │ └── ThreadResourceBinder.java ├── test └── net │ └── azib │ └── ipscan │ ├── config │ ├── CommandLineProcessorTest.java │ ├── ComponentRegistryTest.java │ ├── ConfigTest.java │ ├── GUIConfigTest.java │ ├── LabelsTest.java │ ├── LoggerFactoryTest.java │ ├── NamedListConfigTest.java │ └── OpenersConfigTest.java │ ├── core │ ├── PluginLoaderTest.java │ ├── PortIteratorTest.java │ ├── ScannerDispatcherThreadTest.java │ ├── ScannerTest.java │ ├── ScanningResultComparatorTest.java │ ├── ScanningResultListTest.java │ ├── ScanningSubjectTest.java │ ├── net │ │ ├── ARPPingerTest.java │ │ ├── AbstractPingerTest.java │ │ ├── CombinedUnprivilegedPingerTest.java │ │ ├── JavaPingerTest.java │ │ ├── PingerRegistryTest.java │ │ ├── TCPPingerTest.java │ │ ├── UDPPingerTest.java │ │ └── WindowsPingerTest.java │ ├── state │ │ ├── ScanningStateTest.java │ │ └── StateMachineTest.java │ ├── test-plugin.jar │ └── values │ │ ├── InetAddressHolderTest.java │ │ ├── IntegerWithUnitTest.java │ │ ├── NotAvailableTest.java │ │ ├── NotScannedTest.java │ │ └── NumericRangeListTest.java │ ├── di │ └── InjectorTest.java │ ├── exporters │ ├── AbstractExporterTestCase.java │ ├── CSVExporterTest.java │ ├── ExportProcessorTest.java │ ├── ExporterRegistryTest.java │ ├── IPListExporterTest.java │ ├── TXTExporterTest.java │ ├── XMLExporterTest.java │ ├── import-broken.txt │ └── import.txt │ ├── feeders │ ├── FeederTestUtils.java │ ├── FileFeederTest.java │ ├── RandomFeederTest.java │ ├── RangeFeederTest.java │ └── RescanFeederTest.java │ ├── fetchers │ ├── AbstractFetcherTestCase.java │ ├── FetcherRegistryTest.java │ ├── HostnameFetcherTest.java │ ├── IPFetcherTest.java │ ├── LinuxMACFetcherTest.java │ ├── MACFetcherTest.java │ ├── MACVendorFetcherTest.java │ ├── PacketLossFetcherTest.java │ ├── PingFetcherTest.java │ ├── PingTTLFetcherTest.java │ └── PortsFetcherTest.java │ ├── gui │ ├── GUITest.java │ ├── InputDialogTest.java │ ├── PreferencesDialogTest.java │ ├── SWTTestCase.java │ ├── SelectFetchersDialogTest.java │ ├── StatisticsDialogTest.java │ ├── actions │ │ ├── GotoActionsTest.java │ │ ├── OpenerLauncherTest.java │ │ └── StartStopScanningActionTest.java │ ├── feeders │ │ ├── AbstractFeederGUITest.java │ │ └── FeederGUIRegistryTest.java │ └── fetchers │ │ └── PortTextFetcherPrefsTest.java │ └── util │ ├── GoogleAnalyticsTest.java │ ├── InetAddressUtilsTest.java │ ├── MDNSResolverTest.java │ ├── NetBIOSResolverTest.java │ └── SequenceIteratorTest.java └── update-mac-vendors.sh /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Versions (please copy from the About dialog or complete manually):** 27 | - Version of Angry IP Scanner 28 | - OS, version, CPU architecture 29 | - Java version, vendor (`java -version`) - or if Windows installer was used with bundled Java 30 | 31 | **Logs:** 32 | - Please run Angry IP Scanner from Terminal and see if any relevant logs were written. Paste them here: 33 | - Windows: `jre\bin\java -jar ipscan.exe` (inside of installation directory, e.g. C:\Program Files\Angry IP Scanner) 34 | - Mac: `Angry\ IP\ Scanner.app/Contents/MacOS/ipscan` 35 | - Linux: `ipscan` or `java -jar ipscan.jar` 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for Angry IP Scanner 4 | title: '' 5 | labels: 'feature-request' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | 3 | # Number of days of inactivity before an Issue is closed for lack of response 4 | daysUntilClose: 14 5 | # Label requiring a response 6 | responseRequiredLabel: more-information-needed 7 | # Comment to post when closing an Issue for lack of response. Set to `false` to disable 8 | closeComment: > 9 | This issue has been automatically closed because there has been no response 10 | to our request for more information from the original author. With only the 11 | information that is currently in the issue, we don't have enough information 12 | to take action. Please reach out if you have or find the answers we need so 13 | that we can investigate further. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /generated 3 | /test-coverage 4 | /.gradle 5 | /build 6 | /lib/*src.zip 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | /workspace.xml 2 | /compiler.xml 3 | /jarRepositories.xml 4 | # GitHub Copilot persisted chat sessions 5 | /copilot/chatSessions 6 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ipscan -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 32 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/dictionaries/anton.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | azib 5 | icmp 6 | ipscan 7 | pico 8 | pinger 9 | pingers 10 | prefs 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Unit_tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 17 | 19 | false 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # This file is for those not familiar with Java 2 | # Use ./gradlew instead of make! 3 | 4 | info: 5 | ./gradlew info 6 | 7 | clean: 8 | ./gradlew clean 9 | 10 | all: 11 | ./gradlew all 12 | 13 | current: 14 | ./gradlew current 15 | 16 | linux: 17 | ./gradlew linux 18 | 19 | linux64: 20 | ./gradlew linux64 21 | 22 | win32: 23 | ./gradlew win32 24 | 25 | win64: 26 | ./gradlew win64 27 | 28 | mac: 29 | ./gradlew mac 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angry IP Scanner 2 | 3 | This is the source code of Angry IP Scanner, licensed with GPL v2. [Official site](https://angryip.org/) 4 | 5 | The code is written mostly in Java (currently, source level 11). 6 | [SWT library from Eclipse project](https://eclipse.org/swt/) is used for GUI that provides native components for each supported platform. 7 | 8 | The project runs on Linux, Windows and macOS. 9 | 10 | ## Helping / Contributing 11 | 12 | As there are millions of different networks, configurations and devices, please help with submitting a **Pull Request** if something 13 | doesn't work as you expect (especially macOS users). Any problem is easy to fix if you have an environment to reproduce it 😀 14 | 15 | For that, download [Intellij IDEA community edition](https://www.jetbrains.com/idea/download/) and open the cloned project. 16 | Then, you can run Angry IP Scanner in Debug mode and put a breakpoint into the [desired Fetcher class](src/net/azib/ipscan/fetchers). 17 | 18 | ## Building [![Actions Status](https://github.com/angryip/ipscan/workflows/CI/badge.svg)](https://github.com/angryip/ipscan/actions) 19 | 20 | Use Gradle for building a package for your desired platform: 21 | 22 | `./gradlew` or `make` in the project dir for the list of available targets. 23 | 24 | `./gradlew current` would build the app for your current platform 25 | 26 | The resulting binaries will be put into the `build/libs` directory. 27 | Run jar files with `java -jar `. 28 | 29 | Deb and rpm packages can be built only on Linux (tested on Ubuntu). 30 | Windows installer can be built on Windows only. 31 | 32 | `./gradlew all` will build packages for all OS (tested on Ubuntu only, see dependencies below). 33 | 34 | ### Dependencies 35 | 36 | On Ubuntu install the following packages: 37 | ``` 38 | sudo apt install openjdk-11-jdk rpm fakeroot 39 | ``` 40 | 41 | Install OpenJDK on other platforms as you usually do it. 42 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | * SWT Error: no more handles (empty modal window appears) 2 | * Retrieve value for any fetcher from context menu 3 | * Monitoring mode (which IPs appear/disappear) 4 | * UX: button for netmask application? 5 | * Graalvm native-image to build binary 6 | 7 | * Use ServiceLoader for plugins 8 | * Use ipify for /iplocate 9 | * Add URLFetcher with configurable URL and JSON/XPath expression 10 | * WHOIS fetcher 11 | 12 | * Windows: net stop SharedAccess 13 | * gtk sort direction arrows 14 | * advanced exporting options dialog (with append checkbox) 15 | * Enable/Disable ports (without resetting) 16 | * Opener Launchers to the details window 17 | * multiple port support web-detect, opening in browser selects scanned ports if available 18 | * add new fetchers by configuration of PortTextFetcher 19 | * public XSL for XMLExporter 20 | * Easier adding/removing of columns to the result table (without resetting the results) 21 | * command-line: support favorites 22 | * command-line: add netmask support to the range feeder 23 | * find not-null for column 24 | * export/import of settings (profiles or tie with Favorites?) 25 | * display friendly names of ports 26 | * preferences profiles (tied to favorites?) 27 | * free text (advanced) feeder 28 | * saving and restoring of results together with all options 29 | * advanced find (firefox-like) with options Find Next, Find Previoius, Select all matches 30 | * count occurencies of search (either separate or included) 31 | * diff with saved 32 | * show distinct values for a column 33 | * SWT bug: deleting of many IPs at once is very slow (freezes the ipscan) due to the sorting of provided indices 34 | 35 | * use jpcap for raw packet injection and ARP scanning 36 | * startup as root option 37 | * compile librocksaw for mac and linux64 38 | -------------------------------------------------------------------------------- /build-native-image.sh: -------------------------------------------------------------------------------- 1 | ~/apps/graalvm-ce-java11-20.3.0/bin/native-image -jar build/libs/ipscan-linux64-*.jar --no-fallback --allow-incomplete-classpath -H:IncludeResources='messages.*$' -H:IncludeResources=mac-vendors.txt -H:IncludeResources='images/.*$' 2 | -------------------------------------------------------------------------------- /config/logging.properties: -------------------------------------------------------------------------------- 1 | # java.util.logging configuration 2 | # pass its location with -Djava.util.logging.config.file=config/logging.properties 3 | 4 | handlers = java.util.logging.ConsoleHandler 5 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 6 | java.util.logging.ConsoleHandler.level = ALL 7 | 8 | .level = FINER 9 | -------------------------------------------------------------------------------- /ext/deb-bundle/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: ipscan 2 | Section: net 3 | Version: VERSION 4 | Priority: optional 5 | Architecture: ARCH 6 | Installed-Size: 1940 7 | Depends: DEPENDS java11-runtime 8 | Maintainer: Anton Keks 9 | License: GPL-2 10 | Description: Angry IP Scanner - fast and friendly IP Scanner 11 | Angry IP Scanner is a cross-platform network scanner written in Java. 12 | It can scan IP-based networks in any range, scan ports, and resolve 13 | other information. 14 | The program provides an easy to use GUI interface and is very extensible, 15 | see https://angryip.org/ for more information. 16 | -------------------------------------------------------------------------------- /ext/deb-bundle/DEBIAN/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: ipscan 3 | Upstream-Contact: Anton Keks 4 | Source: https://github.com/angryip/ipscan 5 | 6 | Files: * 7 | Copyright: 2005-2022 Anton Keks & contributors 8 | License: GPL-2+ 9 | 10 | License: GPL-2+ 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | . 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | . 21 | You should have received a copy of the GNU General Public License along 22 | with this program; if not, write to the Free Software Foundation, Inc., 23 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | . 25 | On Debian systems, the full text of the GNU General Public 26 | License version 2 can be found in the file 27 | '/usr/share/common-licenses/GPL-2'. 28 | -------------------------------------------------------------------------------- /ext/deb-bundle/usr/bin/ipscan: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | java=$JAVA_HOME/bin/java 3 | [ ! -e "$java" ] && java=java 4 | "$java" --add-opens java.base/java.net=ALL-UNNAMED -jar /usr/lib*/ipscan/ipscan*.jar "$@" 5 | [ $? != 0 ] && notify-send "You need Java/OpenJDK 11+ to run ipscan" 6 | -------------------------------------------------------------------------------- /ext/deb-bundle/usr/share/applications/ipscan.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Name=Angry IP Scanner 4 | Comment=Fast and friendly network scanner 5 | GenericName=Fast and friendly network scanner 6 | Keywords=angry;ipscan;ip;scan;scanner 7 | Exec=sh /usr/bin/ipscan 8 | Terminal=false 9 | Type=Application 10 | Icon=ipscan 11 | Categories=Application;Network;Internet; 12 | StartupWMClass=Angry IP Scanner 13 | StartupNotify=true 14 | -------------------------------------------------------------------------------- /ext/deb-bundle/usr/share/doc/ipscan/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: angryip 3 | Upstream-Contact: Anton Keks 4 | Source: https://github.com/angryip/ipscan/ 5 | 6 | Files: * 7 | Copyright: 2004-2018 Anton Keks 8 | License: GPL-2+ 9 | 10 | License: GPL-2+ 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | . 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | . 21 | You should have received a copy of the GNU General Public License along 22 | with this program; if not, write to the Free Software Foundation, Inc., 23 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | . 25 | On Debian systems, the full text of the GNU General Public 26 | License version 2 can be found in the file 27 | '/usr/share/common-licenses/GPL-2'. 28 | -------------------------------------------------------------------------------- /ext/deb-bundle/usr/share/metainfo/ipscan.appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ipscan.desktop 4 | CC0-1.0 5 | GPL-2.0+ 6 | Angry IP Scanner 7 | Fast and friendly network scanner 8 | https://angryip.org/images/icon.png 9 | ipscan.desktop 10 | 11 |

Angry IP Scanner (or simply ipscan) is an open-source and cross-platform network scanner designed to be fast and simple to use. It scans IP addresses and ports as well as has many other features.

It is widely used by network administrators and just curious users around the world, including large and small enterprises, banks, and government agencies.

13 |
14 | 15 | Network 16 | Internet 17 | 18 | https://angryip.org/ 19 | https://github.com/angryip/ipscan/issues 20 | https://angryip.org/faq/ 21 | 22 | 23 | https://angryip.org/screenshots/ipscan-ubuntu.png 24 | Scan was performed 25 | 26 | 27 |
28 | -------------------------------------------------------------------------------- /ext/jna.pro: -------------------------------------------------------------------------------- 1 | -keepclassmembers class com.sun.jna.** { 2 | ; 3 | ; 4 | } 5 | 6 | -keepclassmembers class * extends com.sun.jna.** { 7 | ; 8 | ; 9 | } 10 | -------------------------------------------------------------------------------- /ext/mac-bundle/Angry IP Scanner.app/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleExecutable 6 | ipscan 7 | CFBundleGetInfoString 8 | APPNAME VERSION - fast and friendly network scanner 9 | CFBundleIconFile 10 | ipscan.icns 11 | CFBundleIdentifier 12 | net.azib.ipscan 13 | CFBundleName 14 | APPNAME 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | VERSION 19 | CFBundleSignature 20 | ????? 21 | CFBundleVersion 22 | VERSION_NUM 23 | NSPrincipalClass 24 | NSApplication 25 | NSHighResolutionCapable 26 | 27 | NSRequiresAquaSystemAppearance 28 | 29 | LSRequiresNativeExecution 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ext/mac-bundle/Angry IP Scanner.app/Contents/MacOS/ipscan: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | BASEDIR=$(dirname "$0") 3 | java="$BASEDIR/jre/bin/java" 4 | if [ ! -e "$java" ]; then java=java; fi 5 | exec "$java" --add-opens java.base/java.net=ALL-UNNAMED -XstartOnFirstThread -jar "$BASEDIR"/ipscan*.jar 6 | -------------------------------------------------------------------------------- /ext/mac-bundle/Angry IP Scanner.app/Contents/Resources/ipscan.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/mac-bundle/Angry IP Scanner.app/Contents/Resources/ipscan.icns -------------------------------------------------------------------------------- /ext/rpmbuild/SPECS/ipscan.spec: -------------------------------------------------------------------------------- 1 | Summary: Angry IP Scanner - fast and friendly network scanner 2 | Name: ipscan 3 | Version: RPM_VERSION 4 | Release: 1%{?dist} 5 | License: GPLv2+ 6 | Group: Applications/Internet 7 | BuildRoot: %{_builddir}/%{name} 8 | URL: https://angryip.org/ 9 | Packager: Anton Keks 10 | Requires: java-11 11 | 12 | %description 13 | Angry IP Scanner is a cross-platform network scanner written in Java. 14 | It can scan IP-based networks in any range, scan ports, and resolve 15 | other information. 16 | 17 | The program provides an easy to use GUI interface and is very extensible, 18 | see https://angryip.org/ for more information. 19 | 20 | %prep 21 | 22 | %build 23 | 24 | %install 25 | rm -rf $RPM_BUILD_ROOT 26 | mkdir -p $RPM_BUILD_ROOT/%{_libdir}/ipscan $RPM_BUILD_ROOT/%{_datadir}/applications $RPM_BUILD_ROOT/%{_datadir}/pixmaps $RPM_BUILD_ROOT/%{_bindir} 27 | cp ../../%{name}-%{platform}-VERSION.jar $RPM_BUILD_ROOT/%{_libdir}/ipscan/ 28 | cp ../../../../ext/deb-bundle/usr/share/applications/ipscan.desktop $RPM_BUILD_ROOT/%{_datadir}/applications/ 29 | cp ../../../../resources/images/icon128.png $RPM_BUILD_ROOT/%{_datadir}/pixmaps/ipscan.png 30 | cp ../../../../ext/deb-bundle/usr/bin/ipscan $RPM_BUILD_ROOT/%{_bindir}/ 31 | chmod a+x $RPM_BUILD_ROOT/%{_bindir}/ipscan 32 | 33 | %clean 34 | rm -rf $RPM_BUILD_ROOT 35 | 36 | %files 37 | %defattr(-,root,root,-) 38 | %{_libdir}/ipscan/%{name}-%{platform}-VERSION.jar 39 | %{_datadir}/applications/ipscan.desktop 40 | %{_datadir}/pixmaps/ipscan.png 41 | %{_bindir}/ipscan 42 | -------------------------------------------------------------------------------- /ext/win-installer/.gitignore: -------------------------------------------------------------------------------- 1 | /nsis-* 2 | /AppFiles 3 | -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/header-r.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/header-r.bmp -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/header-uninstall-r.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/header-uninstall-r.bmp -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/header-uninstall.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/header-uninstall.bmp -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/header.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/header.bmp -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/installer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/installer.ico -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/uninstaller.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/uninstaller.ico -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/welcomefinish-uninstall.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/welcomefinish-uninstall.bmp -------------------------------------------------------------------------------- /ext/win-installer/Installer/InstallerGraphics/welcomefinish.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-installer/Installer/InstallerGraphics/welcomefinish.bmp -------------------------------------------------------------------------------- /ext/win-launcher/.gitignore: -------------------------------------------------------------------------------- 1 | /*.res 2 | -------------------------------------------------------------------------------- /ext/win-launcher/build.cmd: -------------------------------------------------------------------------------- 1 | :: MinGW C compiler & tools must be installed and added to PATH 2 | windres version.rc -O coff -o version.res 3 | gcc -g0 -s launcher.c version.res -o launcher.exe -mwindows 4 | -------------------------------------------------------------------------------- /ext/win-launcher/launcher.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/ext/win-launcher/launcher.exe -------------------------------------------------------------------------------- /ext/win-launcher/version.rc: -------------------------------------------------------------------------------- 1 | 1 ICON "../../resources/images/icon.ico" 2 | 1 VERSIONINFO 3 | FILEVERSION 3,9,9,9 4 | PRODUCTVERSION 3,9,9,9 5 | BEGIN 6 | BLOCK "StringFileInfo" 7 | BEGIN 8 | BLOCK "040904E4" 9 | BEGIN 10 | VALUE "CompanyName", "angryip.org" 11 | VALUE "FileDescription", "Angry IP Scanner - fast and friendly network scanner" 12 | VALUE "InternalName", "ipscan" 13 | VALUE "LegalCopyright", "Anton Keks" 14 | VALUE "OriginalFilename", "ipscan.exe" 15 | VALUE "ProductName", "Angry IP Scanner" 16 | VALUE "ProductVersion", "3+" 17 | END 18 | END 19 | BLOCK "VarFileInfo" 20 | BEGIN 21 | VALUE "Translation", 0x409, 1252 22 | END 23 | END 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=--add-opens java.base/java.net=ALL-UNNAMED 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /resources/images/buttons/fetchers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/fetchers.png -------------------------------------------------------------------------------- /resources/images/buttons/fetchers@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/fetchers@2x.png -------------------------------------------------------------------------------- /resources/images/buttons/kill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/kill.png -------------------------------------------------------------------------------- /resources/images/buttons/kill@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/kill@2x.png -------------------------------------------------------------------------------- /resources/images/buttons/prefs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/prefs.png -------------------------------------------------------------------------------- /resources/images/buttons/prefs@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/prefs@2x.png -------------------------------------------------------------------------------- /resources/images/buttons/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/start.png -------------------------------------------------------------------------------- /resources/images/buttons/start@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/start@2x.png -------------------------------------------------------------------------------- /resources/images/buttons/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/stop.png -------------------------------------------------------------------------------- /resources/images/buttons/stop@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/buttons/stop@2x.png -------------------------------------------------------------------------------- /resources/images/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon.ico -------------------------------------------------------------------------------- /resources/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon.png -------------------------------------------------------------------------------- /resources/images/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon128.png -------------------------------------------------------------------------------- /resources/images/icon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon256.png -------------------------------------------------------------------------------- /resources/images/icon32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon32.ico -------------------------------------------------------------------------------- /resources/images/icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon32.png -------------------------------------------------------------------------------- /resources/images/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/icon48.png -------------------------------------------------------------------------------- /resources/images/list/alive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/alive.png -------------------------------------------------------------------------------- /resources/images/list/alive@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/alive@2x.png -------------------------------------------------------------------------------- /resources/images/list/dead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/dead.png -------------------------------------------------------------------------------- /resources/images/list/dead@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/dead@2x.png -------------------------------------------------------------------------------- /resources/images/list/ports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/ports.png -------------------------------------------------------------------------------- /resources/images/list/ports@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/ports@2x.png -------------------------------------------------------------------------------- /resources/images/list/unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/unknown.png -------------------------------------------------------------------------------- /resources/images/list/unknown@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/images/list/unknown@2x.png -------------------------------------------------------------------------------- /resources/mac-vendors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/resources/mac-vendors.txt -------------------------------------------------------------------------------- /resources/messages_et.properties: -------------------------------------------------------------------------------- 1 | # Estonian translation (incomplete!!!) 2 | menu.scan=&Fail 3 | menu.scan.newWindow=&Uus aken 4 | menu.scan.exportAll=&Salvesta kõik... 5 | menu.scan.exportSelection=Salvesta &valitud... 6 | menu.scan.quit=Sul&ge 7 | menu.goto=&Mine 8 | menu.goto.find=&Otsi... 9 | menu.commands=&Käsud 10 | menu.commands.details=&Detailid 11 | menu.commands.rescan=Skaneeri &uuesti 12 | menu.commands.delete=Kus&tuta 13 | menu.commands.copy=Kopeeri &aadress 14 | menu.commands.copyDetails=&Kopeeri detailid 15 | menu.commands.open=&Ava 16 | menu.favorites=&Lemmikud 17 | menu.favorites.add=&Lisa käesolev... 18 | menu.favorites.edit=&Redigeeri lemmikuid... 19 | menu.tools=&Vahendid 20 | menu.tools.preferences=&Seaded... 21 | menu.help=&Abi 22 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/CommandProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.config; 8 | 9 | /** 10 | * Interface for providing of various commands to the application 11 | * 12 | * @author Anton Keks 13 | */ 14 | public interface CommandProcessor { 15 | boolean shouldAutoStart(); 16 | boolean shouldAutoQuit(); 17 | } 18 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/CommentsConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.config; 8 | 9 | import net.azib.ipscan.core.ScanningResult; 10 | 11 | import java.net.InetAddress; 12 | import java.util.prefs.Preferences; 13 | 14 | /** 15 | * CommentsConfig - a class for encapsulating of loading/storing of comments. 16 | * 17 | * @author Anton Keks 18 | */ 19 | public class CommentsConfig { 20 | private Preferences preferences; 21 | 22 | public CommentsConfig(Preferences preferences) { 23 | // use a separate node for comments - they can get large 24 | this.preferences = preferences.node("comments"); 25 | } 26 | 27 | public String getComment(InetAddress address, String mac) { 28 | String comment = null; 29 | if (mac != null) comment = preferences.get(mac, null); 30 | if (comment == null) comment = preferences.get(address.getHostAddress(), null); 31 | return comment; 32 | } 33 | 34 | public String getComment(ScanningResult result) { 35 | return getComment(result.getAddress(), result.getMac()); 36 | } 37 | 38 | public void setComment(ScanningResult result, String comment) { 39 | String key = result.getAddress().getHostAddress(); 40 | 41 | if (result.getMac() != null) { 42 | // remove ip-based comment if we set a mac-based one 43 | preferences.remove(key); 44 | String mac = result.getMac(); 45 | if (mac != null) key = mac; 46 | } 47 | 48 | if (comment == null || comment.isEmpty()) 49 | preferences.remove(key); 50 | else 51 | preferences.put(key, comment); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/ComponentRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.config; 7 | 8 | import net.azib.ipscan.core.PluginLoader; 9 | import net.azib.ipscan.di.Injector; 10 | import net.azib.ipscan.exporters.*; 11 | import net.azib.ipscan.fetchers.*; 12 | 13 | /** 14 | * This class is the dependency injection configuration 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class ComponentRegistry { 19 | public void register(Injector i) throws InstantiationException, IllegalAccessException, ClassNotFoundException { 20 | i.register(IPFetcher.class, PingFetcher.class, PingTTLFetcher.class, HostnameFetcher.class, PortsFetcher.class); 21 | i.register(MACFetcher.class, (MACFetcher) Class.forName(MACFetcher.class.getPackage().getName() + 22 | (Platform.WINDOWS ? ".WinMACFetcher" : Platform.LINUX ? ".LinuxMACFetcher" : ".UnixMACFetcher")).newInstance()); 23 | i.register(CommentFetcher.class, FilteredPortsFetcher.class, WebDetectFetcher.class, HTTPSenderFetcher.class, 24 | NetBIOSInfoFetcher.class, PacketLossFetcher.class, HTTPProxyFetcher.class, MACVendorFetcher.class); 25 | i.register(TXTExporter.class, CSVExporter.class, XMLExporter.class, IPListExporter.class, SQLExporter.class); 26 | } 27 | 28 | public Injector init() throws Exception { 29 | return init(true); 30 | } 31 | 32 | public Injector init(boolean withGUI) throws Exception { 33 | Injector i = new Injector(); 34 | new ConfigModule().register(i); 35 | new ComponentRegistry().register(i); 36 | if (withGUI) { 37 | new GUIRegistry().register(i); 38 | new PluginLoader().getClasses().forEach(i::require); 39 | } 40 | return i; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/ConfigModule.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import net.azib.ipscan.di.Injector; 4 | 5 | import java.util.prefs.Preferences; 6 | 7 | public class ConfigModule { 8 | public void register(Injector i) { 9 | Config config = Config.getConfig(); 10 | i.register(Config.class, config); 11 | i.register(Labels.class, Labels.getInstance()); 12 | i.register(Preferences.class, config.getPreferences()); 13 | i.register(ScannerConfig.class, config.forScanner()); 14 | i.register(OpenersConfig.class, config.forOpeners()); 15 | i.register(FavoritesConfig.class, config.forFavorites()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/FavoritesConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.config; 7 | 8 | import net.azib.ipscan.feeders.FeederCreator; 9 | 10 | import java.util.prefs.Preferences; 11 | 12 | /** 13 | * FavoritesConfig 14 | * 15 | * @author Anton Keks 16 | */ 17 | public class FavoritesConfig extends NamedListConfig { 18 | 19 | public FavoritesConfig(Preferences preferences) { 20 | super(preferences, "favorites"); 21 | } 22 | 23 | public void add(String key, FeederCreator feederCreator) { 24 | StringBuilder serializedFeeder = new StringBuilder(feederCreator.getFeederId()); 25 | serializedFeeder.append('\t'); 26 | for (String part : feederCreator.serialize()) { 27 | serializedFeeder.append(part).append(":::"); 28 | } 29 | super.add(key, serializedFeeder.toString()); 30 | } 31 | 32 | public String getFeederId(String key) { 33 | String value = get(key); 34 | int indexOf = value.indexOf('\t'); 35 | return value.substring(0, indexOf); 36 | } 37 | 38 | public String[] getSerializedParts(String key) { 39 | String value = get(key); 40 | int indexOf = value.indexOf('\t'); 41 | return value.substring(indexOf+1).split(":::"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/GUIRegistry.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import net.azib.ipscan.core.state.StateMachine; 4 | import net.azib.ipscan.di.Injector; 5 | import net.azib.ipscan.feeders.FeederRegistry; 6 | import net.azib.ipscan.gui.SWTAwareStateMachine; 7 | import net.azib.ipscan.gui.feeders.*; 8 | import org.eclipse.swt.SWT; 9 | import org.eclipse.swt.widgets.Button; 10 | import org.eclipse.swt.widgets.Display; 11 | import org.eclipse.swt.widgets.Menu; 12 | import org.eclipse.swt.widgets.Shell; 13 | 14 | public class GUIRegistry { 15 | public void register(Injector i) { 16 | Display display = Display.getDefault(); 17 | i.register(Display.class, display); 18 | i.register(GUIConfig.class, Config.getConfig().forGUI()); 19 | 20 | Shell shell = new Shell(); 21 | i.register(Shell.class, shell); 22 | i.register(Menu.class, new Menu(shell, SWT.BAR)); 23 | i.register(FeederSelectionCombo.class, new FeederSelectionCombo(i.require(ControlsArea.class))); 24 | i.register(Button.class, new Button(i.require(ControlsArea.class), SWT.NONE)); 25 | 26 | SWTAwareStateMachine stateMachine = new SWTAwareStateMachine(display); 27 | i.register(SWTAwareStateMachine.class, stateMachine); 28 | i.register(StateMachine.class, stateMachine); 29 | i.register(RangeFeederGUI.class, RandomFeederGUI.class, FileFeederGUI.class); 30 | 31 | i.register(FeederRegistry.class, i.require(FeederGUIRegistry.class)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.config; 7 | 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * LoggerFactory is an easy way to obtain Logger instances. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class LoggerFactory { 16 | 17 | /** 18 | * @return Logger instance initialized to the name of the calling class. 19 | */ 20 | public static Logger getLogger() { 21 | Throwable t = new Throwable(); 22 | StackTraceElement directCaller = t.getStackTrace()[1]; 23 | return Logger.getLogger(directCaller.getClassName()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/config/Platform.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.config; 7 | 8 | import static java.lang.Double.parseDouble; 9 | 10 | /** 11 | * This class provides constants for distinguishing between various platforms. 12 | * However, platform-specific behaviour must be kept at minimum. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class Platform { 17 | 18 | private static final String OS_NAME = System.getProperty("os.name"); 19 | 20 | public static final boolean ARCH_64 = System.getProperty("os.arch").contains("64"); 21 | 22 | /** Mac OS detection :-) */ 23 | public static final boolean MAC_OS = OS_NAME.contains("OS X"); 24 | 25 | /** Linux */ 26 | public static final boolean LINUX = OS_NAME.contains("Linux"); 27 | 28 | /** Any Windows version */ 29 | public static final boolean WINDOWS = OS_NAME.startsWith("Windows"); 30 | 31 | /** Crippled-down version of Windows (no RawSockets, TCP rate limiting, etc */ 32 | public static final boolean CRIPPLED_WINDOWS = WINDOWS && !OS_NAME.contains("Server") && between(parseDouble(System.getProperty("os.version").substring(0, 3)), 5.1, 6.1); 33 | 34 | private static boolean between(double x, double min, double max) { 35 | return x >= min && x < max; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/LibraryLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core; 8 | 9 | import java.io.*; 10 | 11 | /** 12 | * Utility class for loading of JNI libraries from jar files. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class LibraryLoader { 17 | 18 | /** 19 | * Loads native library from the jar file (storing it in the temp dir) 20 | * @param library JNI library name 21 | */ 22 | public static void loadLibrary(String library) { 23 | String filename = System.mapLibraryName(library); 24 | String fullFilename = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + filename; 25 | try { 26 | // try to load from the temp dir (in case it is already there) 27 | System.load(fullFilename); 28 | } 29 | catch (UnsatisfiedLinkError err2) { 30 | try { 31 | // try to extract from the jar 32 | InputStream is = LibraryLoader.class.getClassLoader().getResourceAsStream(filename); 33 | if (is == null) { 34 | throw new IOException(filename + " not found in the jar file (classpath)"); 35 | } 36 | byte[] buffer = new byte[4096]; 37 | OutputStream os = new FileOutputStream(fullFilename); 38 | int read; 39 | while ((read = is.read(buffer)) != -1) { 40 | os.write(buffer, 0, read); 41 | } 42 | os.close(); 43 | is.close(); 44 | new File(fullFilename).setExecutable(true, false); 45 | System.load(fullFilename); 46 | } 47 | catch (IOException ioe) { 48 | throw new RuntimeException("Unable to extract native library: " + library, ioe); 49 | } 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core; 8 | 9 | /** 10 | * Base interface for all plugins. 11 | * 12 | * @author Anton Keks 13 | */ 14 | public interface Plugin { 15 | /** 16 | * @return unique ID of the pluggable, representing it 17 | */ 18 | String getId(); 19 | 20 | /** 21 | * @return localized name of this pluggable (most likely resolved using it's id) 22 | */ 23 | String getName(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/ScannerDispatcherThreadFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core; 7 | 8 | import net.azib.ipscan.config.ScannerConfig; 9 | import net.azib.ipscan.core.state.StateMachine; 10 | import net.azib.ipscan.feeders.Feeder; 11 | 12 | public class ScannerDispatcherThreadFactory { 13 | private ScanningResultList scanningResults; 14 | private Scanner scanner; 15 | private StateMachine stateMachine; 16 | private ScannerConfig scannerConfig; 17 | 18 | public ScannerDispatcherThreadFactory(ScanningResultList scanningResults, Scanner scanner, StateMachine stateMachine, ScannerConfig scannerConfig) { 19 | this.scanningResults = scanningResults; 20 | this.scanner = scanner; 21 | this.stateMachine = stateMachine; 22 | this.scannerConfig = scannerConfig; 23 | } 24 | 25 | public ScannerDispatcherThread createScannerThread(Feeder feeder, ScanningProgressCallback progressCallback, ScanningResultCallback resultsCallback) { 26 | return new ScannerDispatcherThread(feeder, scanner, stateMachine, progressCallback, scanningResults, scannerConfig, resultsCallback); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/ScanningProgressCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core; 7 | 8 | import java.net.InetAddress; 9 | 10 | /** 11 | * This callback is called on scanning state updates. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public interface ScanningProgressCallback { 16 | 17 | /** 18 | * This method is called on scanning progress updates. 19 | * There are no guarantees that this method is called on every 20 | * scanning iteration. 21 | * 22 | * @param currentAddress currently scanned IP address, can be null 23 | * @param runningThreads number of currently running threads 24 | * @param percentageComplete value from 0 to 100, showing how much work 25 | * is already done. 26 | */ 27 | void updateProgress(InetAddress currentAddress, int runningThreads, int percentageComplete); 28 | } 29 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/ScanningResultCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core; 7 | 8 | /** 9 | * This callback is called to consume scanning results. 10 | * 11 | * @author Anton Keks 12 | */ 13 | public interface ScanningResultCallback { 14 | 15 | /** 16 | * This method is called just before starting to retrieve 17 | * scanning results for the specified address. 18 | * @param result empty results holder for a single address 19 | * @return the method should return an int 20 | */ 21 | void prepareForResults(ScanningResult result); 22 | 23 | /** 24 | * This method is called when scanning results are ready. 25 | * @param results filled results holder for a single address 26 | */ 27 | void consumeResults(ScanningResult results); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/ScanningResultComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core; 7 | 8 | import net.azib.ipscan.core.values.Empty; 9 | import net.azib.ipscan.core.values.NotAvailable; 10 | 11 | import java.util.Comparator; 12 | 13 | public class ScanningResultComparator implements Comparator { 14 | 15 | private int index; 16 | private boolean ascending; 17 | 18 | @SuppressWarnings("unchecked") 19 | public int compare(ScanningResult r1, ScanningResult r2) { 20 | Object val1 = r1.getValues().get(index); 21 | Object val2 = r2.getValues().get(index); 22 | 23 | if (val1 == null) 24 | val1 = NotAvailable.VALUE; 25 | if (val2 == null) 26 | val2 = NotAvailable.VALUE; 27 | 28 | int result; 29 | if (val1 == val2) { 30 | result = 0; 31 | } 32 | else 33 | if (val1.getClass() == val2.getClass() && !(val1 instanceof String) && val1 instanceof Comparable) { 34 | // both are the same type and Comparable 35 | result = ((Comparable)val1).compareTo(val2); 36 | } 37 | else { 38 | if (val1 instanceof Empty) 39 | result = ((Empty)val1).compareTo(val2); 40 | else 41 | if (val2 instanceof Empty) 42 | result = -((Empty)val2).compareTo(val1); 43 | else { 44 | // otherwise compare String representations 45 | result = val1.toString().compareToIgnoreCase(val2.toString()); 46 | } 47 | } 48 | 49 | if (result == 0 && index != 0) { 50 | // if values are equal, order them according to the IPs 51 | result = ((Comparable)r1.getValues().get(0)).compareTo(r2.getValues().get(0)); 52 | } 53 | 54 | return result * (ascending ? 1 : -1); 55 | } 56 | 57 | public void byIndex(int index, boolean ascending) { 58 | this.index = index; 59 | this.ascending = ascending; 60 | 61 | // this ensures that all Empty objects are always at the end 62 | Empty.setSortDirection(ascending); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/UserErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core; 7 | 8 | import net.azib.ipscan.config.Labels; 9 | 10 | /** 11 | * Exception for throwing in case of user errors. 12 | * These generally result in showing an error message. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class UserErrorException extends RuntimeException { 17 | public UserErrorException(String label) { 18 | super(label); 19 | } 20 | 21 | public UserErrorException(String label, Throwable cause) { 22 | super(label, cause); 23 | } 24 | 25 | public UserErrorException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | public UserErrorException(String label, String rawInfo) { 30 | super(Labels.getLabel("exception.UserErrorException." + label) + rawInfo); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/ARPPinger.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import net.azib.ipscan.fetchers.MACFetcher; 5 | 6 | import java.io.IOException; 7 | 8 | import static java.lang.System.currentTimeMillis; 9 | 10 | public class ARPPinger implements Pinger { 11 | private MACFetcher macFetcher; 12 | private Pinger trigger; 13 | 14 | public ARPPinger(MACFetcher macFetcher, JavaPinger trigger) { 15 | // WinMACFetcher sends an actual ARP request, so no previous UDP request is needed 16 | this(macFetcher, macFetcher.getClass().getSimpleName().startsWith("Win") ? null : (Pinger) trigger); 17 | } 18 | 19 | ARPPinger(MACFetcher macFetcher, Pinger trigger) { 20 | this.macFetcher = macFetcher; 21 | this.trigger = trigger; 22 | } 23 | 24 | @Override public PingResult ping(ScanningSubject subject, int count) throws IOException { 25 | if (trigger != null) count -= count / 2; 26 | PingResult result = new PingResult(subject.getAddress(), count); 27 | for (int i = 0; i < count; i++) { 28 | long start = currentTimeMillis(); 29 | if (trigger != null) { 30 | // this should issue an ARP request for the IP 31 | result.merge(trigger.ping(subject, 1)); 32 | } 33 | String mac = macFetcher.scan(subject); 34 | if (mac != null) result.addReply(currentTimeMillis() - start); 35 | } 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/CombinedUnprivilegedPinger.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.net; 8 | 9 | import net.azib.ipscan.core.ScanningSubject; 10 | 11 | import java.io.IOException; 12 | 13 | import static java.lang.Math.max; 14 | 15 | /** 16 | * CombinedUnprivilegedPinger - uses both UDP and TCP for pinging. 17 | * A better default alternative for unprivileged users. 18 | * 19 | * @author Anton Keks 20 | */ 21 | public class CombinedUnprivilegedPinger implements Pinger { 22 | private TCPPinger tcpPinger; 23 | private UDPPinger udpPinger; 24 | 25 | public CombinedUnprivilegedPinger(TCPPinger tcpPinger, UDPPinger udpPinger) { 26 | this.tcpPinger = tcpPinger; 27 | this.udpPinger = udpPinger; 28 | } 29 | 30 | public PingResult ping(ScanningSubject subject, int count) throws IOException { 31 | // try UDP first - it should be more reliable in general 32 | int udpCountInitialCount = max(1, count / 2); 33 | PingResult udpResult = udpPinger.ping(subject, udpCountInitialCount); 34 | if (udpResult.isAlive()) 35 | return udpResult.merge(udpPinger.ping(subject, count - udpCountInitialCount)); 36 | 37 | // fallback to TCP - it may detect some hosts UDP cannot 38 | return tcpPinger.ping(subject, count); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/JavaPinger.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.config.ScannerConfig; 4 | import net.azib.ipscan.core.ScanningSubject; 5 | 6 | import java.io.IOException; 7 | import java.net.ConnectException; 8 | 9 | import static java.lang.System.currentTimeMillis; 10 | 11 | public class JavaPinger implements Pinger { 12 | private int timeout; 13 | 14 | public JavaPinger(ScannerConfig config) { 15 | this.timeout = config.pingTimeout; 16 | } 17 | 18 | @Override 19 | public PingResult ping(ScanningSubject subject, int count) throws IOException { 20 | PingResult result = new PingResult(subject.getAddress(), count); 21 | for (int i = 0; i < count; i++) { 22 | try { 23 | long start = currentTimeMillis(); 24 | if (subject.getAddress().isReachable(timeout)) 25 | result.addReply(currentTimeMillis() - start); 26 | } 27 | catch (ConnectException e) { 28 | // these happen on Mac 29 | } 30 | } 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/PingResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core.net; 7 | 8 | import java.net.InetAddress; 9 | 10 | /** 11 | * The result of pinging 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class PingResult { 16 | InetAddress address; 17 | 18 | private int ttl; 19 | private long totalTime; 20 | private long longestTime; 21 | private int packetCount; 22 | private int replyCount; 23 | private boolean timeoutAdaptationAllowed; 24 | 25 | public PingResult(InetAddress address, int packetCount) { 26 | this.address = address; 27 | this.packetCount = packetCount; 28 | } 29 | 30 | public void addReply(long time) { 31 | replyCount++; 32 | if (time > longestTime) 33 | longestTime = time; 34 | totalTime += time; 35 | // this is for ports fetcher, etc 36 | timeoutAdaptationAllowed = replyCount > 2; 37 | } 38 | 39 | public int getTTL() { 40 | return ttl; 41 | } 42 | 43 | public void setTTL(int ttl) { 44 | this.ttl = ttl; 45 | } 46 | 47 | public int getAverageTime() { 48 | return (int)(totalTime / replyCount); 49 | } 50 | 51 | public int getLongestTime() { 52 | return (int)longestTime; 53 | } 54 | 55 | public int getPacketLoss() { 56 | return packetCount - replyCount; 57 | } 58 | 59 | public int getPacketLossPercent() { 60 | if (replyCount > 0) 61 | return (this.getPacketLoss() * 100) / packetCount; 62 | else 63 | return 100; 64 | } 65 | 66 | public int getPacketCount() { 67 | return packetCount; 68 | } 69 | 70 | public int getReplyCount() { 71 | return replyCount; 72 | } 73 | 74 | /** 75 | * @return true in case at least one reply was received 76 | */ 77 | public boolean isAlive() { 78 | return replyCount > 0; 79 | } 80 | 81 | public void enableTimeoutAdaptation() { 82 | if (isAlive()) 83 | timeoutAdaptationAllowed = true; 84 | } 85 | 86 | public boolean isTimeoutAdaptationAllowed() { 87 | return timeoutAdaptationAllowed; 88 | } 89 | 90 | PingResult merge(PingResult result) { 91 | this.packetCount += result.packetCount; 92 | this.replyCount += result.replyCount; 93 | return this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/Pinger.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core.net; 7 | 8 | import net.azib.ipscan.core.ScanningSubject; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Pingers check if hosts are alive 14 | * 15 | * @author Anton Keks 16 | */ 17 | public interface Pinger extends AutoCloseable { 18 | /** 19 | * Issues the specified number of pings and 20 | * waits for replies. 21 | * 22 | * @param count number of pings to perform 23 | */ 24 | PingResult ping(ScanningSubject subject, int count) throws IOException; 25 | 26 | @Override default void close() throws IOException {} 27 | } 28 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/WinIpHlp.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.core.net.WinIpHlpDll.Ip6SockAddrByRef; 4 | import net.azib.ipscan.core.net.WinIpHlpDll.IpAddrByVal; 5 | 6 | import java.net.InetAddress; 7 | 8 | public class WinIpHlp { 9 | public static IpAddrByVal toIpAddr(InetAddress address) { 10 | IpAddrByVal addr = new IpAddrByVal(); 11 | addr.bytes = address.getAddress(); 12 | return addr; 13 | } 14 | 15 | public static Ip6SockAddrByRef toIp6Addr(InetAddress address) { 16 | Ip6SockAddrByRef addr = new Ip6SockAddrByRef(); 17 | addr.bytes = address.getAddress(); 18 | return addr; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/net/WinKernel32.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import com.sun.jna.Library; 4 | import com.sun.jna.Native; 5 | 6 | public interface WinKernel32 extends Library { 7 | WinKernel32 dll = Loader.load(); 8 | class Loader { 9 | public static WinKernel32 load() { 10 | return Native.loadLibrary("kernel32", WinKernel32.class); 11 | } 12 | } 13 | 14 | int GetLastError(); 15 | } 16 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/state/ScanningState.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.state; 8 | 9 | 10 | /** 11 | * ScanningState enum - all possible states. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public enum ScanningState { 16 | 17 | IDLE, 18 | STARTING, 19 | SCANNING, 20 | STOPPING, 21 | KILLING, 22 | RESTARTING; 23 | 24 | /** 25 | * Transitions the state to the next one. 26 | * Note: not all states have the default next state; 27 | */ 28 | ScanningState next() { 29 | switch (this) { 30 | case IDLE: return STARTING; 31 | case STARTING: return SCANNING; 32 | case SCANNING: return STOPPING; 33 | case STOPPING: return KILLING; 34 | case RESTARTING: return SCANNING; 35 | default: return null; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/state/StateTransitionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.state; 8 | 9 | import net.azib.ipscan.core.state.StateMachine.Transition; 10 | 11 | /** 12 | * StateTransitionListener 13 | * 14 | * @author Anton Keks 15 | */ 16 | public interface StateTransitionListener { 17 | 18 | /** 19 | * Notifies on transition to the specified state. 20 | * @param state 21 | * @param transition 22 | */ 23 | void transitionTo(ScanningState state, Transition transition); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/values/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.values; 8 | 9 | /** 10 | * Base class for values that contain no embedded value, e.g. n/a, n/s 11 | * 12 | * @author Anton Keks 13 | */ 14 | public abstract class Empty implements Comparable { 15 | 16 | static int sortDirection = 1; 17 | 18 | /** 19 | * @param ascending changes the sorting behavior of all Empty objects, 20 | * passing true here will make all Empty objects to be greater than any other objects, 21 | * passing false will do otherwise. This needs to be set to make all Empty objects always 22 | * appear at the end of the sorted list. 23 | */ 24 | public static void setSortDirection(boolean ascending) { 25 | Empty.sortDirection = ascending ? 1 : -1; 26 | } 27 | 28 | public int compareTo(Object that) { 29 | if (this == that) 30 | return 0; 31 | // this value is either smaller or greater than any other object (except null) 32 | return sortDirection; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/values/InetAddressHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.values; 8 | 9 | import java.net.InetAddress; 10 | 11 | /** 12 | * InetAddressHolder - a comparable holder of IP addresses 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class InetAddressHolder implements Comparable { 17 | 18 | private String s; 19 | private byte[] a; 20 | 21 | public InetAddressHolder(InetAddress address) { 22 | s = address.getHostAddress(); 23 | a = address.getAddress(); 24 | } 25 | 26 | public int compareTo(InetAddressHolder that) { 27 | byte[] b1 = this.a; 28 | byte[] b2 = that.a; 29 | 30 | // compare each byte 31 | for (int i = 0; i < b1.length; i++) { 32 | if (b1[i] == b2[i]) 33 | continue; 34 | else 35 | if ((b1[i]&0xFF) > (b2[i]&0xFF)) 36 | return 1; 37 | else 38 | return -1; 39 | } 40 | // all bytes are equal 41 | return 0; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return s; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return s.hashCode(); 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) { 56 | if (this == obj) 57 | return true; 58 | if (obj == null) 59 | return false; 60 | if (getClass() != obj.getClass()) 61 | return false; 62 | final InetAddressHolder other = (InetAddressHolder) obj; 63 | if (s == null) { 64 | if (other.s != null) 65 | return false; 66 | } 67 | else if (!s.equals(other.s)) 68 | return false; 69 | return true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/values/IntegerWithUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core.values; 7 | 8 | import net.azib.ipscan.config.Labels; 9 | 10 | /** 11 | * IntegerWithUnit - an Integer value together with a unit, e.g. "10 ms". 12 | * TODO: IntegerWithUnitTest 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class IntegerWithUnit implements Comparable { 17 | 18 | private int value; 19 | private String unitLabel; 20 | 21 | public IntegerWithUnit(int value, String unitLabel) { 22 | this.value = value; 23 | this.unitLabel = unitLabel; 24 | } 25 | 26 | public int intValue() { 27 | return value; 28 | } 29 | 30 | public String toString() { 31 | return value + Labels.getLabel("unit." + unitLabel); 32 | } 33 | 34 | public int hashCode() { 35 | return value; 36 | } 37 | 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (obj instanceof IntegerWithUnit) 44 | return value == ((IntegerWithUnit) obj).value; 45 | return false; 46 | } 47 | 48 | public int compareTo(IntegerWithUnit n) { 49 | if (this == n) 50 | return 0; 51 | if (n == null) 52 | return 1; 53 | return value == n.value ? 0 : value > n.value ? 1 : -1; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/values/NotAvailable.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.values; 2 | 3 | import net.azib.ipscan.config.Config; 4 | 5 | /** 6 | * The value for displaying in the result list, meaning that the actual value is unknown, 7 | * because it wasn't resolved successfully. 8 | * 9 | * @author Anton Keks 10 | */ 11 | public class NotAvailable extends Empty { 12 | public static final NotAvailable VALUE = new NotAvailable(); 13 | 14 | private NotAvailable() {} 15 | 16 | /** 17 | * Displays a user-friendly text string :-) 18 | */ 19 | public String toString() { 20 | return Config.getConfig().forScanner().notAvailableText; 21 | } 22 | 23 | @Override 24 | public int compareTo(Object that) { 25 | // n/a < n/s 26 | if (that == NotScanned.VALUE) 27 | return -sortDirection; 28 | return super.compareTo(that); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/core/values/NotScanned.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.values; 2 | 3 | import net.azib.ipscan.config.Config; 4 | 5 | /** 6 | * The value for displaying in the result list, meaning that the actual value is unknown, 7 | * because it was not scanned. 8 | * 9 | * @author Anton Keks 10 | */ 11 | public class NotScanned extends Empty { 12 | public static final NotScanned VALUE = new NotScanned(); 13 | 14 | private NotScanned() {} 15 | 16 | /** 17 | * Displays a user-friendly text string :-) 18 | */ 19 | public String toString() { 20 | return Config.getConfig().forScanner().notScannedText; 21 | } 22 | 23 | @Override 24 | public int compareTo(Object that) { 25 | // n/s > n/a 26 | if (that == NotAvailable.VALUE) 27 | return sortDirection; 28 | return super.compareTo(that); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/di/InjectException.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.di; 2 | 3 | public class InjectException extends RuntimeException { 4 | public InjectException(String message, Throwable e) { 5 | super(message, e); 6 | } 7 | 8 | public InjectException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/AbstractExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.exporters; 8 | 9 | import net.azib.ipscan.config.Labels; 10 | 11 | import java.io.*; 12 | 13 | /** 14 | * Helper base class of all built-in exporters 15 | * 16 | * @author Anton Keks 17 | */ 18 | public abstract class AbstractExporter implements Exporter { 19 | protected PrintWriter output; 20 | protected boolean append; 21 | 22 | public String getName() { 23 | return Labels.getLabel(getId()); 24 | } 25 | 26 | public void shouldAppendTo(File file) { 27 | this.append = true; 28 | } 29 | 30 | public void start(OutputStream outputStream, String feederInfo) throws IOException { 31 | output = new PrintWriter(new OutputStreamWriter(outputStream)); 32 | } 33 | 34 | public void end() throws IOException { 35 | // this does the flush internally as well 36 | if (output.checkError()) 37 | throw new IOException(); 38 | } 39 | 40 | @Override public void nextAddressResults(Object[] results) throws IOException { 41 | } 42 | 43 | public Exporter clone() { 44 | try { 45 | return (Exporter) super.clone(); 46 | } 47 | catch (CloneNotSupportedException e) { 48 | throw new RuntimeException(e); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/CSVExporter.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.exporters; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * CSV Exporter 7 | * 8 | * @author Anton Keks 9 | */ 10 | public class CSVExporter extends AbstractExporter { 11 | 12 | /* CSV delimiter character */ 13 | static final char DELIMETER = ','; 14 | /* Delimiter escaping character (if data contains DELIMETER) */ 15 | static final char DELIMETER_ESCAPED = '.'; 16 | 17 | public CSVExporter() {} 18 | 19 | public String getId() { 20 | return "exporter.csv"; 21 | } 22 | 23 | public String getFilenameExtension() { 24 | return "csv"; 25 | } 26 | 27 | public void setFetchers(String[] fetcherNames) throws IOException { 28 | if (!append) { 29 | output.write(csvSafeString(fetcherNames[0])); 30 | for (int i = 1; i < fetcherNames.length; i++) { 31 | output.write(DELIMETER); 32 | output.write(csvSafeString(fetcherNames[i])); 33 | } 34 | output.println(); 35 | } 36 | } 37 | 38 | public void nextAddressResults(Object[] results) throws IOException { 39 | output.write(csvSafeString(results[0])); 40 | for (int i = 1; i < results.length; i++) { 41 | Object result = results[i]; 42 | output.write(DELIMETER); 43 | output.write(csvSafeString(result)); 44 | } 45 | output.println(); 46 | } 47 | 48 | /** 49 | * @return a safe string to be output in CSV format (it doesn't contain the DELIMETER) 50 | */ 51 | String csvSafeString(Object o) { 52 | if (o == null) 53 | return ""; 54 | return o.toString().replace(DELIMETER, DELIMETER_ESCAPED); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/Exporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.exporters; 7 | 8 | import net.azib.ipscan.core.Plugin; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.io.OutputStream; 13 | 14 | /** 15 | * An Exporter is a class, which is able to export scanning results into a 16 | * specific output format. 17 | * 18 | * This interface is callback-like. Each method of it is called when more 19 | * data is available for writing. 20 | * 21 | * The sequence of calling: 22 | * start, setFetchers, nextAddressResult, ..., end 23 | * 24 | * Exporters are created by cloning (prototype pattern). 25 | * 26 | * @author Anton Keks 27 | */ 28 | public interface Exporter extends Cloneable, Plugin { 29 | /** 30 | * @return the filename extension of the file type this Exporter produces (like txt, html, etc) 31 | */ 32 | String getFilenameExtension(); 33 | 34 | /** 35 | * Tells the exporter that it should append to the specified file instead of creating a new one. 36 | * @param file the file that the appending will be directed to, so that the Exporter can prepare the file before it will start appending. 37 | */ 38 | void shouldAppendTo(File file); 39 | 40 | /** 41 | * Called on start of the exporting. 42 | * @param outputStream this OutputStream should be used to output exported data. 43 | * @param feederInfo summary of feeder preferences, which were used for this scan 44 | */ 45 | void start(OutputStream outputStream, String feederInfo) throws IOException; 46 | 47 | /** 48 | * Called when no more data is available for exporting. This is the last 49 | * method, which is called on any exporter. 50 | */ 51 | void end() throws IOException; 52 | 53 | /** 54 | * Called after the start to provide the whole list of fetchers 55 | */ 56 | void setFetchers(String[] fetcherNames) throws IOException; 57 | 58 | /** 59 | * Called to provide the actual scanning results for the IP address. 60 | * @param results the results, returned by the Fetcher. This is an array of String 61 | * most of the time or objects, which provide toString() methods. 62 | * The IP address itself is the first element in the provided array. 63 | * Any element of results can be null. 64 | */ 65 | void nextAddressResults(Object[] results) throws IOException; 66 | 67 | /** 68 | * Clones the Exporter instance 69 | */ 70 | Object clone() throws CloneNotSupportedException; 71 | } 72 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/ExporterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.exporters; 7 | 8 | import net.azib.ipscan.core.UserErrorException; 9 | 10 | /** 11 | * Exception for throwing in case of problems in Exporters. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class ExporterException extends UserErrorException { 16 | public ExporterException(String message) { 17 | super(message); 18 | } 19 | 20 | public ExporterException(String message, Throwable cause) { 21 | super(message); 22 | initCause(cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/ExporterRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.exporters; 7 | 8 | import java.util.Iterator; 9 | import java.util.LinkedHashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * The registry of all Exporters. 15 | * It registers both plugins and builtins. 16 | * 17 | * @author Anton Keks 18 | */ 19 | public class ExporterRegistry implements Iterable { 20 | /** All available Exporter implementations, Map of Exporter instances (prototypes) */ 21 | private Map exporters; 22 | 23 | public ExporterRegistry(List registeredExporters) { 24 | exporters = new LinkedHashMap<>(); 25 | 26 | for (Exporter exporter : registeredExporters) { 27 | exporters.put(exporter.getFilenameExtension(), exporter); 28 | } 29 | } 30 | 31 | /** 32 | * Iterates Exporter instances within this Registry 33 | */ 34 | public Iterator iterator() { 35 | return exporters.values().iterator(); 36 | } 37 | 38 | /** 39 | * Creates a new exporter instance examining the extension of the provided file name 40 | * @param fileName the file name (with extension) 41 | * @throws ExporterException in case such exporter is not registered 42 | */ 43 | public Exporter createExporter(String fileName) throws ExporterException { 44 | int extensionPos = fileName.lastIndexOf('.') + 1; 45 | String extension = fileName.substring(extensionPos); 46 | 47 | Exporter prototype = exporters.get(extension); 48 | if (prototype == null) { 49 | throw new ExporterException("exporter.unknown"); 50 | } 51 | try { 52 | return (Exporter) prototype.clone(); 53 | } 54 | catch (CloneNotSupportedException e) { 55 | // this is not possible 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/IPListExporter.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.exporters; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.core.PortIterator; 5 | import net.azib.ipscan.core.values.NumericRangeList; 6 | import net.azib.ipscan.fetchers.IPFetcher; 7 | import net.azib.ipscan.fetchers.PortsFetcher; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * IP List Exporter 13 | *

14 | * Exports only IP:port info, outputting each distinct IP:port pair on separate line. 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class IPListExporter extends AbstractExporter { 19 | static final char DELIMETER = ':'; 20 | 21 | private int ipFetcherIndex; 22 | private int portsFetcherIndex; 23 | 24 | public IPListExporter() {} 25 | 26 | public String getId() { 27 | return "exporter.ipList"; 28 | } 29 | 30 | public String getFilenameExtension() { 31 | return "lst"; 32 | } 33 | 34 | public void setFetchers(String[] fetcherNames) throws IOException { 35 | ipFetcherIndex = findFetcherById(IPFetcher.ID, fetcherNames); 36 | portsFetcherIndex = findFetcherById(PortsFetcher.ID, fetcherNames); 37 | } 38 | 39 | /** 40 | * Searches for the needed fetcher by name. 41 | * 42 | * @param fetcherId 43 | * @param fetcherNames 44 | * @return fetcher's index 45 | * @throws ExporterException in case fetcher is not found 46 | */ 47 | static int findFetcherById(String fetcherId, String[] fetcherNames) { 48 | String fetcherName = Labels.getLabel(fetcherId); 49 | for (int i = 0; i < fetcherNames.length; i++) { 50 | if (fetcherName.equals(fetcherNames[i])) { 51 | return i; 52 | } 53 | } 54 | throw new ExporterException("fetcher.notFound"); 55 | } 56 | 57 | public void nextAddressResults(Object[] results) throws IOException { 58 | String address = results[ipFetcherIndex].toString(); 59 | Object ports = results[portsFetcherIndex]; 60 | 61 | if (ports instanceof NumericRangeList) { 62 | for (PortIterator i = new PortIterator(ports.toString()); i.hasNext(); ) { 63 | output.println(address + DELIMETER + i.next()); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/exporters/SQLExporter.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.exporters; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | /** 7 | * SQL Exporter 8 | *

9 | * Exports results as an SQL inserts, suitable for sqlite, mysql, etc, 10 | * optionally preceding by a 'create table'. 11 | * 12 | * @author Anton Keks 13 | * @author Francesco Ambrosini 14 | */ 15 | public class SQLExporter extends AbstractExporter { 16 | 17 | static final String TABLE_NAME = "scan"; 18 | 19 | static final char COMMA = ','; 20 | 21 | public String getId() { 22 | return "exporter.sql"; 23 | } 24 | 25 | public String getFilenameExtension() { 26 | return "sql"; 27 | } 28 | 29 | public void start(OutputStream outputStream, String feederInfo) throws IOException { 30 | super.start(outputStream, feederInfo); 31 | 32 | if (!append) { 33 | output.println("DROP TABLE IF EXISTS" + TABLE_NAME + ";"); 34 | } 35 | } 36 | 37 | public void setFetchers(String[] fetcherNames) throws IOException { 38 | if (!append) { 39 | output.print("CREATE TABLE " + TABLE_NAME + " (`" + fetcherNames[0] + "` varchar(20)"); 40 | for (int i = 1; i < fetcherNames.length; i++) { 41 | output.print(COMMA); 42 | output.print(" `" + fetcherNames[i] + "` "); 43 | output.print("varchar(20)"); //Default type 44 | } 45 | output.println(");"); 46 | } 47 | } 48 | 49 | public void nextAddressResults(Object[] results) throws IOException { 50 | output.print("INSERT INTO " + TABLE_NAME + " VALUES ('" + results[0] + "'"); 51 | for (int i = 1; i < results.length; i++) { 52 | Object result = results[i]; 53 | output.print(COMMA); 54 | output.print(" "); 55 | output.print("'" + result + "'"); 56 | } 57 | output.println(");"); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/AbstractFeeder.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.feeders; 8 | 9 | import net.azib.ipscan.config.Labels; 10 | import net.azib.ipscan.core.ScanningSubject; 11 | 12 | import java.net.InetAddress; 13 | import java.net.InterfaceAddress; 14 | import java.net.NetworkInterface; 15 | 16 | import static net.azib.ipscan.util.InetAddressUtils.getInterface; 17 | import static net.azib.ipscan.util.InetAddressUtils.matchingAddress; 18 | 19 | /** 20 | * Helper base class for built-in Feeders 21 | * 22 | * @author Anton Keks 23 | */ 24 | public abstract class AbstractFeeder implements Feeder { 25 | private NetworkInterface netIf; 26 | private InterfaceAddress ifAddr; 27 | 28 | protected void initInterfaces(InetAddress ip) { 29 | this.netIf = getInterface(ip); 30 | this.ifAddr = matchingAddress(netIf, ip.getClass()); 31 | } 32 | 33 | @Override public ScanningSubject subject(InetAddress ip) { 34 | return new ScanningSubject(ip, netIf, ifAddr); 35 | } 36 | 37 | @Override public String getName() { 38 | return Labels.getLabel(getId()); 39 | } 40 | 41 | @Override public boolean isLocalNetwork() { 42 | return ifAddr != null; 43 | } 44 | 45 | @Override public String toString() { 46 | return getName() + ": " + getInfo(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/Feeder.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.feeders; 7 | 8 | import net.azib.ipscan.core.Plugin; 9 | import net.azib.ipscan.core.ScanningSubject; 10 | 11 | import java.net.InetAddress; 12 | 13 | /** 14 | * Interface of a Feeder, which is used to feed scanner with IP addresses. 15 | * Basically, classes implementing Feeder must provide an algorithm of 16 | * sequentially generating the list of scanned IP addresses. 17 | * 18 | * Implementations should be 'immutable', i.e. once created, they should not 19 | * change their internal parameters (getInfo() must always return the same value). 20 | * 21 | * A new instance of Feeder will be created for each scan, passing the required 22 | * parameters to constructor. Default constructor should also be provided in order 23 | * to query name and id of the Feeder. 24 | * 25 | * @author Anton Keks 26 | */ 27 | public interface Feeder extends Plugin { 28 | /** 29 | * @return true in case there are more IPs left for processing 30 | */ 31 | boolean hasNext(); 32 | 33 | /** 34 | * @return the next IP for processing 35 | */ 36 | ScanningSubject next(); 37 | 38 | /** 39 | * @return value from 0 to 100, describing the amount of work already done 40 | */ 41 | int percentageComplete(); 42 | 43 | /** 44 | * @return information about feeder's current settings. 45 | * Used for creation of Favorites, saving to file, etc. 46 | */ 47 | String getInfo(); 48 | 49 | /** 50 | * @return true if scanning LAN addresses, so that ARP, etc can be used 51 | */ 52 | default boolean isLocalNetwork() { 53 | return false; 54 | } 55 | 56 | default ScanningSubject subject(InetAddress ip) { 57 | return new ScanningSubject(ip); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/FeederCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.feeders; 8 | 9 | 10 | /** 11 | * FeederCreator 12 | * 13 | * @author Anton Keks 14 | */ 15 | public interface FeederCreator { 16 | /** 17 | * Initializes a Feeder instance using the parameters, provided by the GUI. 18 | * @return initialized feeder instance 19 | */ 20 | Feeder createFeeder(); 21 | 22 | /** 23 | * @return the feeder id 24 | */ 25 | String getFeederId(); 26 | 27 | /** 28 | * @return the feeder name 29 | */ 30 | String getFeederName(); 31 | 32 | /** 33 | * @return serialized settings to a String 34 | */ 35 | String[] serialize(); 36 | 37 | /** 38 | * Restores previously serialized settings. 39 | * @param parts 40 | */ 41 | void unserialize(String... parts); 42 | 43 | /** 44 | * @return labels corresponding to parts during serialization. 45 | * Used for command-line usage help, etc. 46 | */ 47 | String[] serializePartsLabels(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/FeederException.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.feeders; 7 | 8 | import net.azib.ipscan.core.UserErrorException; 9 | 10 | /** 11 | * Exception for throwing in case of problems with Feeders. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class FeederException extends UserErrorException { 16 | public FeederException(String message) { 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/FeederRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.feeders; 8 | 9 | /** 10 | * FeederRegistry 11 | * 12 | * @author Anton Keks 13 | */ 14 | public interface FeederRegistry extends Iterable { 15 | void select(String feederId); 16 | } 17 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/RescanFeeder.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.feeders; 7 | 8 | import net.azib.ipscan.config.Labels; 9 | import net.azib.ipscan.core.ScanningSubject; 10 | 11 | import java.net.InetAddress; 12 | import java.net.UnknownHostException; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * A Feeder for rescanning - takes a predefined list of IP addresses. 18 | * 19 | * @author Anton Keks 20 | */ 21 | public class RescanFeeder extends AbstractFeeder { 22 | private Feeder originalFeeder; 23 | private List addresses; 24 | 25 | int current; 26 | 27 | /** 28 | * Initializes the RescanFeeder using the old feeder used for the real scan to delegate some calls to. 29 | */ 30 | public RescanFeeder(Feeder originalFeeder, String ... ips) { 31 | this.originalFeeder = originalFeeder; 32 | initAddresses(ips); 33 | } 34 | 35 | /** 36 | * @return the label of the "old" feeder 37 | */ 38 | @Override public String getId() { 39 | return originalFeeder.getId(); 40 | } 41 | 42 | @Override public String getName() { 43 | return Labels.getLabel("feeder.rescan.of") + originalFeeder.getName(); 44 | } 45 | 46 | /** 47 | * Initializes the RescanFeeder with required parameters 48 | * @param ips an array of IP addresses as Strings 49 | */ 50 | private int initAddresses(String ... ips) { 51 | if (ips.length == 0) 52 | throw new IllegalArgumentException("no IP addresses specified"); 53 | 54 | try { 55 | addresses = new ArrayList<>(ips.length); 56 | for (String s : ips) { 57 | addresses.add(InetAddress.getByName(s)); 58 | } 59 | } 60 | catch (UnknownHostException e) { 61 | throw new FeederException("malformedIP"); 62 | } 63 | return ips.length; 64 | } 65 | 66 | @Override public boolean hasNext() { 67 | return current < addresses.size(); 68 | } 69 | 70 | @Override public ScanningSubject next() { 71 | return originalFeeder.subject(addresses.get(current++)); 72 | } 73 | 74 | @Override public int percentageComplete() { 75 | return current * 100 / addresses.size(); 76 | } 77 | 78 | @Override public String getInfo() { 79 | return originalFeeder.getInfo(); 80 | } 81 | 82 | @Override public boolean isLocalNetwork() { 83 | return originalFeeder.isLocalNetwork(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/feeders/SmartTextFeeder.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.feeders; 7 | 8 | import net.azib.ipscan.core.ScanningSubject; 9 | 10 | /** 11 | * Smart text feeder for advanced users. 12 | * 13 | * TODO: implement SmartTextFeeder to accept text, e.g. 14 | * 127.0.0.1-255 15 | * 127.0-10.13-15.1 16 | * 127.0.0.1/24 17 | * 18 | * Warning: IPv4-specific! 19 | * 20 | * @author Anton Keks 21 | */ 22 | public class SmartTextFeeder extends AbstractFeeder { 23 | 24 | public String getId() { 25 | return null; 26 | } 27 | 28 | public SmartTextFeeder(String text) { 29 | // remove all whitespace 30 | text = text.replaceAll("\\w+", ""); 31 | 32 | // extract netmask 33 | int slashPos = text.indexOf('/'); 34 | if (slashPos >= 0) { 35 | //netmask = text.substring(slashPos+1); 36 | text = text.substring(0, slashPos); 37 | } 38 | 39 | //String[] tokens = text.split("\\."); 40 | // TODO: use port list parsing code here 41 | } 42 | 43 | public boolean hasNext() { 44 | return false; 45 | } 46 | 47 | public ScanningSubject next() { 48 | return null; 49 | } 50 | 51 | public int percentageComplete() { 52 | return 0; 53 | } 54 | 55 | public String getInfo() { 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/AbstractFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.fetchers; 7 | 8 | import net.azib.ipscan.config.Config; 9 | import net.azib.ipscan.config.Labels; 10 | 11 | import java.util.MissingResourceException; 12 | import java.util.prefs.Preferences; 13 | 14 | /** 15 | * Convenience base class for built-in fetchers 16 | * 17 | * @author Anton Keks 18 | */ 19 | public abstract class AbstractFetcher implements Fetcher { 20 | 21 | public String getName() { 22 | return Labels.getLabel(getId()); 23 | } 24 | 25 | public String getFullName() { 26 | return getName(); 27 | } 28 | 29 | public String getInfo() { 30 | try { 31 | return Labels.getLabel(getId() + ".info"); 32 | } 33 | catch (MissingResourceException e) { 34 | return null; 35 | } 36 | } 37 | 38 | public Preferences getPreferences() { 39 | return Config.getConfig().getPreferences().node(getId().replace("fetcher.", "")); 40 | } 41 | 42 | public Class getPreferencesClass() { 43 | // no preferences by default 44 | return null; 45 | } 46 | 47 | public void init() { 48 | // nothing's here by default 49 | } 50 | 51 | public void cleanup() { 52 | // nothing's here by default 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/CommentFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | */ 5 | package net.azib.ipscan.fetchers; 6 | 7 | import net.azib.ipscan.config.CommentsConfig; 8 | import net.azib.ipscan.core.ScanningSubject; 9 | 10 | /** 11 | * A fetcher for displaying of user-defined comments about every IP address. 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class CommentFetcher extends AbstractFetcher { 16 | public static final String ID = "fetcher.comment"; 17 | 18 | private CommentsConfig commentsConfig; 19 | 20 | public CommentFetcher(CommentsConfig commentsConfig) { 21 | this.commentsConfig = commentsConfig; 22 | } 23 | 24 | public String getId() { 25 | return ID; 26 | } 27 | 28 | public Object scan(ScanningSubject subject) { 29 | String mac = (String) subject.getParameter(MACFetcher.ID); 30 | return commentsConfig.getComment(subject.getAddress(), mac); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/Fetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | */ 5 | package net.azib.ipscan.fetchers; 6 | 7 | import net.azib.ipscan.core.Plugin; 8 | import net.azib.ipscan.core.ScanningSubject; 9 | import net.azib.ipscan.core.values.NotAvailable; 10 | import net.azib.ipscan.core.values.NotScanned; 11 | import net.azib.ipscan.feeders.Feeder; 12 | 13 | /** 14 | * Interface of all IP Fetchers. 15 | * 16 | * Fetcher is responsible for gathering a certain type of 17 | * information about the provided scanning subject 18 | * (in GUI terms, Fetcher is a column in the results list). 19 | * 20 | * Fetchers do the actual information fetching about each 21 | * scanned IP address. 22 | * 23 | * Instances of this classes are shared among all the threads, 24 | * so implementations must be thread safe and stateless. 25 | * 26 | * @author Anton Keks 27 | */ 28 | public interface Fetcher extends Cloneable, Plugin { 29 | 30 | /** 31 | * @return full name to be displayed in the result table column. 32 | * It may contain a suffix useful to inform users about the fetcher's preferences. 33 | */ 34 | String getFullName(); 35 | 36 | /** 37 | * @return localized help text about the fetcher 38 | */ 39 | String getInfo(); 40 | 41 | /** 42 | * @return the preferences class that may be used for editing of this fetcher's preferences 43 | * or null if no preferences editing is possible 44 | */ 45 | Class getPreferencesClass(); 46 | 47 | /** 48 | * Does the actual fetching. 49 | * @param subject the scanning subject, containing an IP address 50 | * @return the fetched data (a String in most cases), null in case of any error. 51 | * Special values may also be returned, such as {@link NotAvailable} or {@link NotScanned} 52 | */ 53 | Object scan(ScanningSubject subject); 54 | 55 | /** 56 | * Called before scanning has started to do any initialization stuff 57 | */ 58 | default void init(Feeder feeder) { 59 | init(); 60 | } 61 | 62 | default void init() {} 63 | 64 | /** 65 | * Called after the scanning has been completed to do any cleanup needed 66 | */ 67 | void cleanup(); 68 | } 69 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/FetcherException.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.fetchers; 7 | 8 | import net.azib.ipscan.core.UserErrorException; 9 | 10 | public class FetcherException extends UserErrorException { 11 | public FetcherException(String label, Throwable cause) { 12 | super(label, cause); 13 | } 14 | 15 | public FetcherException(String label) { 16 | super(label); 17 | } 18 | 19 | public FetcherException(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/FetcherPrefs.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | /** 10 | * FetcherPrefs - an interface to implement for Fetcher preferences editor classes. 11 | * 12 | * @author Anton Keks 13 | */ 14 | public interface FetcherPrefs { 15 | /** 16 | * Opens a self-maintained GUI editor of concrete fetcher preferences. 17 | * @param fetcher to edit 18 | */ 19 | void openFor(Fetcher fetcher); 20 | } 21 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/FetcherRegistryUpdateListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.fetchers; 7 | 8 | /** 9 | * FetcherRegistryUpdateListener. 10 | * Implement this interface if you need to react to FetcherRegistry updates. 11 | * 12 | * @author Anton Keks 13 | */ 14 | public interface FetcherRegistryUpdateListener { 15 | 16 | /** 17 | * This method is called when the list of selected Fetchers was changed. 18 | * @param fetcherRegistry 19 | */ 20 | void handleUpdateOfSelectedFetchers(FetcherRegistry fetcherRegistry); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.fetchers; 7 | 8 | import net.azib.ipscan.config.ScannerConfig; 9 | import net.azib.ipscan.core.ScanningSubject; 10 | import net.azib.ipscan.core.values.NotScanned; 11 | import net.azib.ipscan.core.values.NumericRangeList; 12 | 13 | import java.util.SortedSet; 14 | 15 | /** 16 | * FilteredPortsFetcher uses the scanning results of PortsFetcher to display filtered ports. 17 | * 18 | * @author Anton Keks 19 | */ 20 | public class FilteredPortsFetcher extends PortsFetcher { 21 | 22 | public FilteredPortsFetcher(ScannerConfig scannerConfig) { 23 | super(scannerConfig); 24 | } 25 | 26 | public String getId() { 27 | return "fetcher.ports.filtered"; 28 | } 29 | 30 | public Object scan(ScanningSubject subject) { 31 | boolean portsScanned = scanPorts(subject); 32 | if (!portsScanned) 33 | return NotScanned.VALUE; 34 | 35 | SortedSet filteredPorts = getFilteredPorts(subject); 36 | return filteredPorts.size() > 0 ? new NumericRangeList(filteredPorts, displayAsRanges) : null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/HTTPProxyFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | import net.azib.ipscan.config.ScannerConfig; 10 | 11 | import java.util.regex.Matcher; 12 | 13 | /** 14 | * HTTPProxyFetcher - detects HTTP proxy on port 3128 (or other requested port) 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class HTTPProxyFetcher extends PortTextFetcher { 19 | public HTTPProxyFetcher(ScannerConfig scannerConfig) { 20 | super(scannerConfig, 3128, "HEAD http://www.google.com HTTP/1.0\r\n\r\n", "^(HTTP/[\\d\\.]+ [23].*)$"); 21 | this.scanOpenPorts = true; 22 | } 23 | 24 | public String getId() { 25 | return "fetcher.httpProxy"; 26 | } 27 | 28 | @Override 29 | protected String getResult(Matcher matcher, int port) { 30 | return port + ": " + super.getResult(matcher, port); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/HTTPSenderFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | import net.azib.ipscan.config.ScannerConfig; 10 | 11 | /** 12 | * HTTPSenderFetcher - allows sending of arbitrary info port and showing the result. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class HTTPSenderFetcher extends PortTextFetcher { 17 | public HTTPSenderFetcher(ScannerConfig scannerConfig) { 18 | super(scannerConfig, 80, "HEAD / HTTP/1.0\r\n\r\n", "Date: (.*)$"); 19 | } 20 | 21 | public String getId() { 22 | return "fetcher.httpSender"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/IPFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | */ 5 | package net.azib.ipscan.fetchers; 6 | 7 | import net.azib.ipscan.core.ScanningSubject; 8 | import net.azib.ipscan.core.values.InetAddressHolder; 9 | 10 | /** 11 | * Dummy fetcher, which is able to return the textual representation 12 | * of the passed IP address. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class IPFetcher extends AbstractFetcher { 17 | public IPFetcher() {} 18 | 19 | public static final String ID = "fetcher.ip"; 20 | 21 | public String getId() { 22 | return ID; 23 | } 24 | 25 | public Object scan(ScanningSubject subject) { 26 | return new InetAddressHolder(subject.getAddress()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/LastAliveTimeFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | import net.azib.ipscan.core.ScanningSubject; 10 | 11 | /** 12 | * LastAliveTimeFetcher 13 | * 14 | * TODO: implement LastAliveTimeFetcher 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class LastAliveTimeFetcher extends AbstractFetcher { 19 | 20 | public String getId() { 21 | // TODO Auto-generated method stub 22 | return null; 23 | } 24 | 25 | public Object scan(ScanningSubject subject) { 26 | // TODO Auto-generated method stub 27 | return null; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/LinuxMACFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.util.stream.Stream; 8 | 9 | import static net.azib.ipscan.fetchers.UnixMACFetcher.getLocalMAC; 10 | 11 | public class LinuxMACFetcher extends MACFetcher { 12 | private static final Path ARP_TABLE = Path.of("/proc/net/arp"); 13 | private int flagsIndex; 14 | private int macIndex; 15 | private int macLength = 17; 16 | 17 | public LinuxMACFetcher() { 18 | String line = arpLines().findFirst().get(); 19 | flagsIndex = line.indexOf("Flags"); 20 | macIndex = line.indexOf("HW addr"); 21 | } 22 | 23 | private static Stream arpLines() { 24 | try { 25 | return Files.lines(ARP_TABLE); 26 | } catch (Exception e) { 27 | return Stream.empty(); 28 | } 29 | } 30 | 31 | @Override public String resolveMAC(ScanningSubject subject) { 32 | try { 33 | String ip = subject.getAddress().getHostAddress(); 34 | return arpLines() 35 | .filter(line -> line.startsWith(ip + " ") && !line.substring(flagsIndex, flagsIndex + 3).equals("0x0")).findFirst() 36 | .map(line -> line.substring(macIndex, macIndex + macLength).toUpperCase()) 37 | .orElse(getLocalMAC(subject)); 38 | } 39 | catch (Exception e) { 40 | return null; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/MACFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import net.azib.ipscan.gui.fetchers.MACFetcherPrefs; 5 | 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public abstract class MACFetcher extends AbstractFetcher { 10 | public static final String ID = "fetcher.mac"; 11 | static final Pattern macAddressPattern = Pattern.compile("([a-fA-F0-9]{1,2}[-:]){5}[a-fA-F0-9]{1,2}"); 12 | static final Pattern leadingZeroesPattern = Pattern.compile("(?<=^|-|:)([A-F0-9])(?=-|:|$)"); 13 | String separator = getPreferences().get("separator", ":"); 14 | 15 | @Override public String getId() { 16 | return ID; 17 | } 18 | 19 | @Override public final String scan(ScanningSubject subject) { 20 | String mac = (String) subject.getParameter(ID); 21 | if (mac == null) mac = resolveMAC(subject); 22 | subject.setParameter(ID, mac); 23 | return replaceSeparator(mac); 24 | } 25 | 26 | protected abstract String resolveMAC(ScanningSubject subject); 27 | 28 | static String bytesToMAC(byte[] bytes) { 29 | StringBuilder mac = new StringBuilder(); 30 | for (byte b : bytes) mac.append(String.format("%02X", b)).append(":"); 31 | if (mac.length() > 0) mac.deleteCharAt(mac.length()-1); 32 | return mac.toString(); 33 | } 34 | 35 | String extractMAC(String line) { 36 | Matcher m = macAddressPattern.matcher(line); 37 | return m.find() ? addLeadingZeroes(m.group().toUpperCase()) : null; 38 | } 39 | 40 | String replaceSeparator(String mac) { 41 | return mac != null ? mac.replace(":", separator) : null; 42 | } 43 | 44 | private static String addLeadingZeroes(String mac) { 45 | return leadingZeroesPattern.matcher(mac).replaceAll("0$1"); 46 | } 47 | 48 | public String getSeparator() { 49 | return separator; 50 | } 51 | 52 | public void setSeparator(String separator) { 53 | this.separator = separator; 54 | } 55 | 56 | @Override public Class getPreferencesClass() { 57 | return MACFetcherPrefs.class; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/MACVendorFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public class MACVendorFetcher extends AbstractFetcher { 12 | public static final String ID = "fetcher.mac.vendor"; 13 | private static Map vendors = new HashMap<>(); 14 | private MACFetcher macFetcher; 15 | 16 | public MACVendorFetcher(MACFetcher macFetcher) { 17 | this.macFetcher = macFetcher; 18 | } 19 | 20 | @Override 21 | public String getId() { 22 | return ID; 23 | } 24 | 25 | @Override 26 | public void init() { 27 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/mac-vendors.txt")))) { 28 | String line; 29 | while ((line = reader.readLine()) != null) { 30 | if (line.isEmpty()) continue; 31 | vendors.put(line.substring(0, 6), line.substring(6)); 32 | } 33 | } 34 | catch (IOException e) { 35 | throw new RuntimeException(e); 36 | } 37 | } 38 | 39 | @Override 40 | public Object scan(ScanningSubject subject) { 41 | String mac = (String)subject.getParameter(MACFetcher.ID); 42 | if (mac == null) { 43 | macFetcher.scan(subject); 44 | mac = (String) subject.getParameter(MACFetcher.ID); 45 | } 46 | return mac != null ? findMACVendor(mac) : null; 47 | } 48 | 49 | String findMACVendor(String mac) { 50 | return vendors.get(mac.replace(":", "").substring(0, 6)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/NetBIOSInfoFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | import net.azib.ipscan.config.LoggerFactory; 10 | import net.azib.ipscan.core.ScanningSubject; 11 | import net.azib.ipscan.util.NetBIOSResolver; 12 | 13 | import java.net.SocketException; 14 | import java.net.SocketTimeoutException; 15 | import java.util.logging.Logger; 16 | 17 | import static java.util.logging.Level.WARNING; 18 | 19 | /** 20 | * NetBIOSInfoFetcher - gathers NetBIOS info about Windows machines. 21 | * Provided for feature-compatibility with version 2.x 22 | * 23 | * @author Anton Keks 24 | */ 25 | public class NetBIOSInfoFetcher extends AbstractFetcher { 26 | public NetBIOSInfoFetcher() {} 27 | 28 | private static final Logger LOG = LoggerFactory.getLogger(); 29 | 30 | public String getId() { 31 | return "fetcher.netbios"; 32 | } 33 | 34 | public Object scan(ScanningSubject subject) { 35 | try (NetBIOSResolver netbios = new NetBIOSResolver(subject.getAdaptedPortTimeout())) { 36 | String[] names = netbios.resolve(subject.getAddress()); 37 | if (names == null) return null; 38 | 39 | String computerName = names[0]; 40 | String userName = names[1]; 41 | String groupName = names[2]; 42 | String macAddress = names[3]; 43 | 44 | return (groupName != null ? groupName + "\\" : "") + 45 | (userName != null ? userName + "@" : "") + 46 | (computerName != null ? computerName + ' ' : "") + '[' + macAddress + ']'; 47 | } 48 | catch (SocketTimeoutException e) { 49 | // this is not a derivative of SocketException 50 | return null; 51 | } 52 | catch (SocketException e) { 53 | // this includes PortUnreachableException 54 | return null; 55 | } 56 | catch (Exception e) { 57 | // bugs? 58 | LOG.log(WARNING, null, e); 59 | return null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/PacketLossFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.ScannerConfig; 4 | import net.azib.ipscan.core.ScanningSubject; 5 | import net.azib.ipscan.core.net.PingResult; 6 | import net.azib.ipscan.core.net.PingerRegistry; 7 | 8 | import static net.azib.ipscan.core.ScanningResult.ResultType.ALIVE; 9 | import static net.azib.ipscan.core.ScanningResult.ResultType.DEAD; 10 | 11 | /** 12 | * PacketLossFetcher shares pinging results with PingFetcher 13 | * and returns the packet loss field of the received packet. 14 | * 15 | * @author Gustavo Pistore 16 | */ 17 | public class PacketLossFetcher extends PingFetcher { 18 | 19 | public PacketLossFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) { 20 | super(pingerRegistry, scannerConfig); 21 | } 22 | 23 | public String getId() { 24 | return "fetcher.packetloss"; 25 | } 26 | 27 | public Object scan(ScanningSubject subject) { 28 | PingResult result = executePing(subject); 29 | subject.setResultType(result.isAlive() ? ALIVE : DEAD); 30 | 31 | return result.getPacketLoss() + "/" + result.getPacketCount() + " (" + result.getPacketLossPercent() + "%)"; 32 | } 33 | } -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/PingTTLFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | */ 5 | package net.azib.ipscan.fetchers; 6 | 7 | import net.azib.ipscan.config.ScannerConfig; 8 | import net.azib.ipscan.core.ScanningResult.ResultType; 9 | import net.azib.ipscan.core.ScanningSubject; 10 | import net.azib.ipscan.core.net.PingResult; 11 | import net.azib.ipscan.core.net.PingerRegistry; 12 | 13 | /** 14 | * PingTTLFetcher shares pinging results with PingFetcher 15 | * and returns the TTL field of the last received packet. 16 | * 17 | * @author Anton Keks 18 | */ 19 | public class PingTTLFetcher extends PingFetcher { 20 | 21 | public PingTTLFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) { 22 | super(pingerRegistry, scannerConfig); 23 | } 24 | 25 | public String getId() { 26 | return "fetcher.ping.ttl"; 27 | } 28 | 29 | public Object scan(ScanningSubject subject) { 30 | PingResult result = executePing(subject); 31 | subject.setResultType(result.isAlive() ? ResultType.ALIVE : ResultType.DEAD); 32 | return result.isAlive() && result.getTTL() > 0 ? result.getTTL() : null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/UnixMACFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import net.azib.ipscan.core.ScanningSubject; 5 | import net.azib.ipscan.util.IOUtils; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.InputStreamReader; 9 | import java.net.SocketException; 10 | 11 | public class UnixMACFetcher extends MACFetcher { 12 | private String arp; 13 | 14 | public UnixMACFetcher() { 15 | if (Platform.LINUX) 16 | arp = "arp -an "; // use BSD-style output 17 | else 18 | arp = "arp -n "; // Mac and other BSD 19 | } 20 | 21 | @Override public String resolveMAC(ScanningSubject subject) { 22 | String ip = subject.getAddress().getHostAddress(); 23 | BufferedReader reader = null; 24 | try { 25 | // highly inefficient implementation, there must be a better way (using JNA?) 26 | Process process = Runtime.getRuntime().exec(arp + ip); 27 | reader = new BufferedReader(new InputStreamReader(process.getInputStream())); 28 | String line; 29 | while ((line = reader.readLine()) != null) { 30 | if (line.contains(ip)) 31 | return extractMAC(line); 32 | } 33 | return getLocalMAC(subject); 34 | } 35 | catch (Exception e) { 36 | return null; 37 | } 38 | finally { 39 | IOUtils.closeQuietly(reader); 40 | } 41 | } 42 | 43 | static String getLocalMAC(ScanningSubject subject) throws SocketException { 44 | return subject.isLocalHost() ? bytesToMAC(subject.getInterface().getHardwareAddress()) : null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/WebDetectFetcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.fetchers; 8 | 9 | import net.azib.ipscan.config.ScannerConfig; 10 | 11 | /** 12 | * WebDetectFetcher - detects the Web server software running on scanned hosts. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class WebDetectFetcher extends PortTextFetcher { 17 | 18 | public WebDetectFetcher(ScannerConfig scannerConfig) { 19 | super(scannerConfig, 80, "HEAD /robots.txt HTTP/1.0\r\n\r\n", "^[Ss]erver:\\s+(.*)$"); 20 | } 21 | 22 | public String getId() { 23 | return "fetcher.webDetect"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/fetchers/WinMACFetcher.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import com.sun.jna.Memory; 4 | import com.sun.jna.Pointer; 5 | import net.azib.ipscan.core.ScanningSubject; 6 | 7 | import java.net.Inet4Address; 8 | 9 | import static net.azib.ipscan.core.net.WinIpHlp.toIpAddr; 10 | import static net.azib.ipscan.core.net.WinIpHlpDll.dll; 11 | 12 | public class WinMACFetcher extends MACFetcher { 13 | @Override public String resolveMAC(ScanningSubject subject) { 14 | if (!(subject.getAddress() instanceof Inet4Address)) return null; // TODO IPv6 support 15 | 16 | Pointer pmac = new Memory(8); 17 | Pointer plen = new Memory(4); 18 | plen.setInt(0, 8); 19 | 20 | int result = dll.SendARP(toIpAddr(subject.getAddress()), 0, pmac, plen); 21 | 22 | if (result != 0) return null; 23 | 24 | byte[] bytes = pmac.getByteArray(0, plen.getInt(0)); 25 | return bytesToMAC(bytes); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/SWTAwareStateMachine.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui; 8 | 9 | import net.azib.ipscan.core.state.StateMachine; 10 | import net.azib.ipscan.core.state.StateTransitionListener; 11 | import org.eclipse.swt.widgets.Display; 12 | 13 | /** 14 | * Extends the generic {@link StateMachine} in order to run state transition notifications 15 | * in the SWT user-interface thread. This will allow {@link StateTransitionListener}s to call SWT methods without 16 | * the bloat of using the {@link Display#asyncExec(Runnable)} themselves. 17 | * 18 | * @author Anton Keks 19 | */ 20 | public class SWTAwareStateMachine extends StateMachine { 21 | private Display display; 22 | 23 | public SWTAwareStateMachine(Display display) { 24 | this.display = display; 25 | } 26 | 27 | @Override 28 | protected void notifyAboutTransition(final Transition transition) { 29 | if (display.isDisposed()) 30 | return; 31 | 32 | // call super asynchronously in the correct thread 33 | display.asyncExec(() -> SWTAwareStateMachine.super.notifyAboutTransition(transition)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/Startup.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui; 2 | 3 | import net.azib.ipscan.config.GUIConfig; 4 | import net.azib.ipscan.config.Labels; 5 | import net.azib.ipscan.config.Platform; 6 | import net.azib.ipscan.config.Version; 7 | import net.azib.ipscan.gui.actions.HelpMenuActions.CheckVersion; 8 | import net.azib.ipscan.util.GoogleAnalytics; 9 | import org.eclipse.swt.widgets.Display; 10 | import org.eclipse.swt.widgets.Shell; 11 | 12 | public class Startup { 13 | private Shell shell; 14 | private GUIConfig guiConfig; 15 | private CheckVersion checkVersion; 16 | 17 | public Startup(Shell shell, GUIConfig guiConfig, CheckVersion checkVersion) { 18 | this.shell = shell; 19 | this.guiConfig = guiConfig; 20 | this.checkVersion = checkVersion; 21 | } 22 | 23 | public void onStart() { 24 | if (guiConfig.isFirstRun) { 25 | new GoogleAnalytics().asyncReport("First run"); 26 | Display.getCurrent().asyncExec(() -> { 27 | GettingStartedDialog dialog = new GettingStartedDialog(); 28 | if (Platform.CRIPPLED_WINDOWS) 29 | dialog.prependText(Labels.getLabel("text.crippledWindowsInfo")); 30 | 31 | shell.forceActive(); 32 | dialog.open(); 33 | guiConfig.isFirstRun = false; 34 | checkForLatestVersion(); 35 | }); 36 | } 37 | else if (!Version.getVersion().equals(guiConfig.lastRunVersion)) { 38 | new GoogleAnalytics().asyncReport("Update " + guiConfig.lastRunVersion + " to " + Version.getVersion()); 39 | guiConfig.lastRunVersion = Version.getVersion(); 40 | } 41 | else if (guiConfig.versionCheckEnabled && System.currentTimeMillis() - guiConfig.lastVersionCheck > 30L * 24 * 3600 * 1000) { 42 | new GoogleAnalytics().asyncReport("Version check " + Version.getVersion()); 43 | checkForLatestVersion(); 44 | } 45 | } 46 | 47 | private void checkForLatestVersion() { 48 | checkVersion.check(false); 49 | guiConfig.lastVersionCheck = System.currentTimeMillis(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/actions/BrowserLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.gui.actions; 7 | 8 | import net.azib.ipscan.core.UserErrorException; 9 | import org.eclipse.swt.program.Program; 10 | 11 | public class BrowserLauncher { 12 | /** 13 | * Opens an URL in the default browser. 14 | */ 15 | public static void openURL(String url) { 16 | if (!Program.launch(url)) throw new UserErrorException("openURL.failed", url); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/feeders/ControlsArea.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.feeders; 2 | 3 | import org.eclipse.swt.SWT; 4 | import org.eclipse.swt.widgets.Composite; 5 | import org.eclipse.swt.widgets.Shell; 6 | 7 | public class ControlsArea extends Composite { 8 | public ControlsArea(Shell parent) { 9 | super(parent, SWT.NONE); 10 | } 11 | 12 | @Override protected void checkSubclass() {} 13 | } 14 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/feeders/FeederArea.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.feeders; 2 | 3 | import org.eclipse.swt.SWT; 4 | import org.eclipse.swt.widgets.Composite; 5 | import org.eclipse.swt.widgets.Shell; 6 | 7 | public class FeederArea extends Composite { 8 | public FeederArea(Shell parent) { 9 | super(parent, SWT.NONE); 10 | } 11 | 12 | @Override protected void checkSubclass() {} 13 | } 14 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/feeders/FeederSelectionCombo.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.feeders; 2 | 3 | import org.eclipse.swt.SWT; 4 | import org.eclipse.swt.widgets.Combo; 5 | import org.eclipse.swt.widgets.Composite; 6 | 7 | public class FeederSelectionCombo extends Combo { 8 | public FeederSelectionCombo(Composite parent) { 9 | super(parent, SWT.READ_ONLY); 10 | } 11 | 12 | @Override protected void checkSubclass() {} 13 | } 14 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/feeders/FileFeederGUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.gui.feeders; 7 | 8 | import net.azib.ipscan.feeders.Feeder; 9 | import net.azib.ipscan.feeders.FileFeeder; 10 | import org.eclipse.swt.SWT; 11 | import org.eclipse.swt.events.SelectionAdapter; 12 | import org.eclipse.swt.events.SelectionEvent; 13 | import org.eclipse.swt.layout.GridData; 14 | import org.eclipse.swt.layout.GridLayout; 15 | import org.eclipse.swt.widgets.Button; 16 | import org.eclipse.swt.widgets.FileDialog; 17 | import org.eclipse.swt.widgets.Label; 18 | import org.eclipse.swt.widgets.Text; 19 | 20 | import static net.azib.ipscan.config.Labels.getLabel; 21 | 22 | /** 23 | * GUI for initialization of FileFeeder. 24 | * 25 | * @author Anton Keks 26 | */ 27 | public class FileFeederGUI extends AbstractFeederGUI { 28 | private Text fileNameText; 29 | 30 | public FileFeederGUI(FeederArea parent) { 31 | super(parent); 32 | feeder = new FileFeeder(); 33 | } 34 | 35 | public void initialize() { 36 | setLayout(new GridLayout(3, false)); 37 | Label fileNameLabel = new Label(this, SWT.NONE); 38 | fileNameText = new Text(this, SWT.BORDER); 39 | Button browseButton = new Button(this, SWT.NONE); 40 | 41 | fileNameLabel.setText(getLabel("feeder.file.name") + ":"); 42 | 43 | fileNameText.setLayoutData(new GridData(160, -1)); 44 | 45 | browseButton.setText(getLabel("feeder.file.browse")); 46 | browseButton.addSelectionListener(new SelectionAdapter() { 47 | public void widgetSelected(SelectionEvent e) { 48 | FileDialog dialog = new FileDialog(getShell()); 49 | dialog.setText(getLabel("feeder.file.browse")); 50 | String fileName = dialog.open(); 51 | if (fileName != null) { 52 | fileNameText.setText(fileName); 53 | fileNameText.setSelection(fileName.length()); 54 | } 55 | } 56 | }); 57 | 58 | pack(); 59 | } 60 | 61 | public Feeder createFeeder() { 62 | feeder = new FileFeeder(fileNameText.getText()); 63 | return feeder; 64 | } 65 | 66 | public String[] serialize() { 67 | return new String[] {fileNameText.getText()}; 68 | } 69 | 70 | public void unserialize(String[] parts) { 71 | fileNameText.setText(parts[0]); 72 | } 73 | 74 | public String[] serializePartsLabels() { 75 | return new String[] {"feeder.file.name"}; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/fetchers/MACFetcherPrefs.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.gui.fetchers; 7 | 8 | import net.azib.ipscan.config.Labels; 9 | import net.azib.ipscan.fetchers.Fetcher; 10 | import net.azib.ipscan.fetchers.FetcherPrefs; 11 | import net.azib.ipscan.fetchers.MACFetcher; 12 | import net.azib.ipscan.gui.AbstractModalDialog; 13 | import net.azib.ipscan.gui.util.LayoutHelper; 14 | import org.eclipse.swt.SWT; 15 | import org.eclipse.swt.layout.FormAttachment; 16 | import org.eclipse.swt.widgets.*; 17 | 18 | public class MACFetcherPrefs extends AbstractModalDialog implements FetcherPrefs { 19 | private MACFetcher fetcher; 20 | private Text separator; 21 | 22 | public void openFor(Fetcher fetcher) { 23 | this.fetcher = (MACFetcher) fetcher; 24 | open(); 25 | } 26 | 27 | @Override 28 | protected void populateShell() { 29 | shell = new Shell(Display.getCurrent().getActiveShell(), SWT.DIALOG_TRIM); 30 | shell.setText(fetcher.getName()); 31 | shell.setLayout(LayoutHelper.formLayout(10, 10, 5)); 32 | 33 | Label separatorLabel = new Label(shell, SWT.NONE); 34 | separatorLabel.setText(Labels.getLabel("fetcher.mac.separator")); 35 | separator = new Text(shell, SWT.BORDER); 36 | separator.setText(fetcher.getSeparator()); 37 | separator.setLayoutData(LayoutHelper.formData(new FormAttachment(0), new FormAttachment(100), new FormAttachment(separatorLabel), null)); 38 | 39 | Button okButton = new Button(shell, SWT.NONE); 40 | okButton.setText(Labels.getLabel("button.OK")); 41 | 42 | Button cancelButton = new Button(shell, SWT.NONE); 43 | cancelButton.setText(Labels.getLabel("button.cancel")); 44 | 45 | positionButtonsInFormLayout(okButton, cancelButton, separator); 46 | 47 | okButton.addListener(SWT.Selection, e -> { 48 | savePreferences(); 49 | close(); 50 | }); 51 | cancelButton.addListener(SWT.Selection, e -> close()); 52 | 53 | shell.pack(); 54 | } 55 | 56 | void savePreferences() { 57 | String text = separator.getText(); 58 | fetcher.setSeparator(text); 59 | fetcher.getPreferences().put("separator", text); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/fetchers/PingFetcherPrefs.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui.fetchers; 8 | 9 | import net.azib.ipscan.fetchers.Fetcher; 10 | import net.azib.ipscan.fetchers.FetcherPrefs; 11 | import net.azib.ipscan.gui.PreferencesDialog; 12 | 13 | /** 14 | * PingFetcherPrefs - just opens the appropriate tab of the PreferencesDialog 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class PingFetcherPrefs implements FetcherPrefs { 19 | 20 | private PreferencesDialog preferencesDialog; 21 | 22 | public PingFetcherPrefs(PreferencesDialog preferencesDialog) { 23 | this.preferencesDialog = preferencesDialog; 24 | } 25 | 26 | public void openFor(Fetcher fetcher) { 27 | preferencesDialog.openTab(0); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/fetchers/PortsFetcherPrefs.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui.fetchers; 8 | 9 | import net.azib.ipscan.fetchers.Fetcher; 10 | import net.azib.ipscan.fetchers.FetcherPrefs; 11 | import net.azib.ipscan.gui.PreferencesDialog; 12 | 13 | /** 14 | * PortsFetcherPrefs - just opens the appropriate tab of the PreferencesDialog 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class PortsFetcherPrefs implements FetcherPrefs { 19 | 20 | private PreferencesDialog preferencesDialog; 21 | 22 | public PortsFetcherPrefs(PreferencesDialog preferencesDialog) { 23 | this.preferencesDialog = preferencesDialog; 24 | } 25 | 26 | public void openFor(Fetcher fetcher) { 27 | preferencesDialog.openTab(1); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/AbstractMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import org.eclipse.swt.SWT; 4 | import org.eclipse.swt.widgets.Shell; 5 | 6 | public abstract class AbstractMenu extends ExtendableMenu { 7 | 8 | public AbstractMenu(Shell parent, int style) { 9 | super(parent, style); 10 | } 11 | 12 | public AbstractMenu(Shell parent) { 13 | super(parent, SWT.DROP_DOWN); 14 | } 15 | 16 | public abstract String getId(); 17 | } 18 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/ColumnsMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.gui.actions.ColumnsActions; 4 | import net.azib.ipscan.gui.actions.ToolsActions; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Shell; 7 | 8 | /** 9 | * ColumnsMenu wrapper for type-safety. 10 | * This is the menu when clicking on a column header. 11 | */ 12 | public class ColumnsMenu extends ExtendableMenu { 13 | public ColumnsMenu(Shell parent, 14 | ColumnsActions.SortBy sortByListener, 15 | ColumnsActions.AboutFetcher aboutListener, 16 | ColumnsActions.FetcherPreferences preferencesListener, 17 | ToolsActions.ChooseFetchers chooseFetchersListener) { 18 | 19 | super(parent, SWT.POP_UP); 20 | 21 | initMenuItem(this, "menu.columns.sortBy", null, null, sortByListener); 22 | initMenuItem(this, "menu.columns.preferences", null, null, preferencesListener); 23 | initMenuItem(this, "menu.columns.about", null, null, aboutListener); 24 | initMenuItem(this, null, null, null, null); 25 | initMenuItem(this, "title.fetchers.select", null, null, chooseFetchersListener); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/CommandsMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.config.Platform; 5 | import net.azib.ipscan.gui.actions.CommandsMenuActions; 6 | import org.eclipse.swt.SWT; 7 | import org.eclipse.swt.widgets.MenuItem; 8 | import org.eclipse.swt.widgets.Shell; 9 | 10 | public class CommandsMenu extends AbstractMenu { 11 | public CommandsMenu(Shell parent, CommandsMenuActions actions, OpenersMenu openersMenu) { 12 | this(parent, SWT.DROP_DOWN, actions, openersMenu); 13 | } 14 | 15 | protected CommandsMenu(Shell parent, int style, CommandsMenuActions actions, OpenersMenu openersMenu) { 16 | super(parent, style); 17 | 18 | initMenuItem(this, "menu.commands.details", null, null, actions.details); 19 | initMenuItem(this, null, null, null, null); 20 | initMenuItem(this, "menu.commands.rescan", "Ctrl+R", SWT.MOD1 | 'R', actions.rescan, true); 21 | initMenuItem(this, "menu.commands.delete", Platform.MAC_OS ? "⌦" : "Del", /* this is not a global key binding */ null, actions.delete, true); 22 | initMenuItem(this, null, null, null, null); 23 | initMenuItem(this, "menu.commands.copy", Platform.MAC_OS ? "⌘C" : "Ctrl+C", /* this is not a global key binding */ null, actions.copyIP); 24 | initMenuItem(this, "menu.commands.copyDetails", null, null, actions.copyIPDetails); 25 | initMenuItem(this, null, null, null, null); 26 | 27 | MenuItem openersMenuItem = new MenuItem(this, SWT.CASCADE); 28 | openersMenuItem.setText(Labels.getLabel(openersMenu.getId())); 29 | openersMenuItem.setMenu(openersMenu); 30 | 31 | // initMenuItem(subMenu, "menu.commands.show", null, initListener()); 32 | } 33 | 34 | @Override 35 | public String getId() { 36 | return "menu.commands"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/ExtendableMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import org.eclipse.swt.SWT; 5 | import org.eclipse.swt.widgets.Listener; 6 | import org.eclipse.swt.widgets.Menu; 7 | import org.eclipse.swt.widgets.MenuItem; 8 | import org.eclipse.swt.widgets.Shell; 9 | 10 | class ExtendableMenu extends Menu { 11 | 12 | public ExtendableMenu(Shell parent, int style) { 13 | super(parent, style); 14 | } 15 | 16 | static MenuItem initMenuItem(Menu parent, String label, String acceleratorText, Integer accelerator, Listener listener) { 17 | return initMenuItem(parent, label, acceleratorText, accelerator, listener, false); 18 | } 19 | 20 | static MenuItem initMenuItem(Menu parent, String label, String acceleratorText, Integer accelerator, Listener listener, boolean disableDuringScanning) { 21 | MenuItem menuItem = new MenuItem(parent, label == null ? SWT.SEPARATOR : SWT.PUSH); 22 | 23 | if (label != null) 24 | menuItem.setText(Labels.getLabel(label) + (acceleratorText != null ? "\t" + acceleratorText : "")); 25 | 26 | if (accelerator != null) 27 | menuItem.setAccelerator(accelerator); 28 | 29 | if (listener != null) 30 | menuItem.addListener(SWT.Selection, listener); 31 | else 32 | menuItem.setEnabled(false); 33 | 34 | if (disableDuringScanning) { 35 | menuItem.setData("disableDuringScanning", true); 36 | } 37 | 38 | return menuItem; 39 | } 40 | 41 | @Override 42 | protected void checkSubclass() { } // allow extending of Menu class 43 | } 44 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/FavoritesMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.gui.actions.FavoritesMenuActions; 4 | import org.eclipse.swt.SWT; 5 | import org.eclipse.swt.widgets.Shell; 6 | 7 | /** 8 | * FavoritesMenu wrapper for type-safety 9 | */ 10 | public class FavoritesMenu extends AbstractMenu { 11 | public FavoritesMenu(Shell parent, 12 | FavoritesMenuActions.Add addListener, 13 | FavoritesMenuActions.Edit editListener, 14 | FavoritesMenuActions.ShowMenu showFavoritesMenuListener) { 15 | 16 | super(parent); 17 | 18 | initMenuItem(this, "menu.favorites.add", "Ctrl+D", SWT.MOD1 | 'D', addListener); 19 | initMenuItem(this, "menu.favorites.edit", null, null, editListener); 20 | initMenuItem(this, null, null, null, null); 21 | 22 | addListener(SWT.Show, showFavoritesMenuListener); 23 | } 24 | 25 | @Override 26 | public String getId() { 27 | return "menu.favorites"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/GotoMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import net.azib.ipscan.gui.actions.GotoMenuActions; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Shell; 7 | 8 | public class GotoMenu extends AbstractMenu { 9 | public GotoMenu(Shell parent, 10 | GotoMenuActions.NextAliveHost nextAliveHost, 11 | GotoMenuActions.NextHostWithInfo nextHostWithInfo, 12 | GotoMenuActions.NextDeadHost nextDeadHost, 13 | GotoMenuActions.PrevAliveHost prevAliveHost, 14 | GotoMenuActions.PrevHostWithInfo prevHostWithInfo, 15 | GotoMenuActions.PrevDeadHost prevDeadHost, 16 | GotoMenuActions.Find find) { 17 | 18 | super(parent); 19 | 20 | var nextHostKey = Platform.MAC_OS ? 'N' : 'H'; 21 | initMenuItem(this, "menu.goto.next.aliveHost", "Ctrl+" + nextHostKey, SWT.MOD1 | nextHostKey, nextAliveHost); 22 | initMenuItem(this, "menu.goto.next.openPort", "Ctrl+J", SWT.MOD1 | 'J', nextHostWithInfo); 23 | initMenuItem(this, "menu.goto.next.deadHost", "Ctrl+K", SWT.MOD1 | 'K', nextDeadHost); 24 | initMenuItem(this, null, null, null, null); 25 | initMenuItem(this, "menu.goto.prev.aliveHost", "Ctrl+Shift+" + nextHostKey, SWT.MOD1 | SWT.MOD2 | nextHostKey, prevAliveHost); 26 | initMenuItem(this, "menu.goto.prev.openPort", "Ctrl+Shift+J", SWT.MOD1 | SWT.MOD2 | 'J', prevHostWithInfo); 27 | initMenuItem(this, "menu.goto.prev.deadHost", "Ctrl+Shift+K", SWT.MOD1 | SWT.MOD2 | 'K', prevDeadHost); 28 | initMenuItem(this, null, null, null, null); 29 | initMenuItem(this, "menu.goto.find", "Ctrl+F", SWT.MOD1 | 'F', find); 30 | } 31 | 32 | @Override 33 | public String getId() { 34 | return "menu.goto"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/HelpMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import net.azib.ipscan.gui.actions.HelpMenuActions; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Shell; 7 | 8 | public class HelpMenu extends AbstractMenu { 9 | public HelpMenu(Shell parent, 10 | HelpMenuActions.GettingStarted gettingStarted, 11 | HelpMenuActions.Website website, 12 | HelpMenuActions.FAQ faq, 13 | HelpMenuActions.Issues issues, 14 | HelpMenuActions.Plugins plugins, 15 | HelpMenuActions.CommandLineUsage commandLineUsage, 16 | HelpMenuActions.CheckVersion checkVersion, 17 | HelpMenuActions.About about) { 18 | 19 | super(parent); 20 | 21 | initMenuItem(this, "menu.help.gettingStarted", !Platform.MAC_OS ? "F1" : null, Platform.MAC_OS ? SWT.HELP : SWT.F1, gettingStarted); 22 | initMenuItem(this, null, null, null, null); 23 | initMenuItem(this, "menu.help.website", null, null, website); 24 | initMenuItem(this, "menu.help.faq", null, null, faq); 25 | initMenuItem(this, "menu.help.issues", null, null, issues); 26 | initMenuItem(this, "menu.help.plugins", null, null, plugins); 27 | initMenuItem(this, null, null, null, null); 28 | initMenuItem(this, "menu.help.cmdLine", null, null, commandLineUsage); 29 | 30 | if (!Platform.MAC_OS) { 31 | // mac will have these in the 'application' menu 32 | initMenuItem(this, null, null, null, null); 33 | initMenuItem(this, "menu.help.checkVersion", null, null, checkVersion); 34 | initMenuItem(this, null, null, null, null); 35 | initMenuItem(this, "menu.help.about", null, null, about); 36 | } 37 | } 38 | 39 | @Override 40 | public String getId() { 41 | return "menu.help"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/OpenersContextMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.gui.actions.CommandsMenuActions.EditOpeners; 4 | import net.azib.ipscan.gui.actions.CommandsMenuActions.ShowOpenersMenu; 5 | import org.eclipse.swt.widgets.Shell; 6 | 7 | public class OpenersContextMenu extends OpenersMenu { 8 | public OpenersContextMenu(Shell parent, EditOpeners editOpenersListener, ShowOpenersMenu showOpenersMenuListener) { 9 | super(parent, editOpenersListener, showOpenersMenuListener); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/OpenersMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.gui.actions.CommandsMenuActions.EditOpeners; 4 | import net.azib.ipscan.gui.actions.CommandsMenuActions.ShowOpenersMenu; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Event; 7 | import org.eclipse.swt.widgets.Shell; 8 | 9 | /** 10 | * OpenersMenu wrapper for type-safety 11 | */ 12 | public class OpenersMenu extends AbstractMenu { 13 | public OpenersMenu(Shell parent, EditOpeners editOpenersListener, ShowOpenersMenu showOpenersMenuListener) { 14 | super(parent); 15 | 16 | initMenuItem(this, "menu.commands.open.edit", null, null, editOpenersListener); 17 | initMenuItem(this, null, null, null, null); 18 | 19 | addListener(SWT.Show, showOpenersMenuListener); 20 | 21 | // run the listener to populate the menu initially and initialize accelerators 22 | Event e = new Event(); 23 | e.widget = this; 24 | showOpenersMenuListener.handleEvent(e); 25 | } 26 | 27 | @Override 28 | public String getId() { 29 | return "menu.commands.open"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/ResultsContextMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.gui.actions.CommandsMenuActions; 4 | import org.eclipse.swt.SWT; 5 | import org.eclipse.swt.widgets.Shell; 6 | 7 | public class ResultsContextMenu extends CommandsMenu { 8 | public ResultsContextMenu(Shell parent, CommandsMenuActions actions, OpenersContextMenu openersMenu) { 9 | super(parent, SWT.POP_UP, actions, openersMenu); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/ScanMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import net.azib.ipscan.gui.actions.ScanMenuActions; 5 | import org.eclipse.swt.SWT; 6 | import org.eclipse.swt.widgets.Shell; 7 | 8 | public class ScanMenu extends AbstractMenu { 9 | 10 | public ScanMenu(Shell parent, 11 | ScanMenuActions.LoadFromFile loadFromFile, 12 | ScanMenuActions.SaveAll saveAll, 13 | ScanMenuActions.SaveSelection saveSelection, 14 | ScanMenuActions.Quit quit) { 15 | 16 | super(parent); 17 | 18 | // initMenuItem(subMenu, "menu.scan.newWindow", "Ctrl+N", new Integer(SWT.MOD1 | 'N'), initListener(FileActions.NewWindow.class)); 19 | // initMenuItem(subMenu, null, null, null, null); 20 | initMenuItem(this, "menu.scan.load", "", SWT.MOD1 | 'O', loadFromFile, true); 21 | initMenuItem(this, "menu.scan.exportAll", "Ctrl+S", SWT.MOD1 | 'S', saveAll, false); 22 | initMenuItem(this, "menu.scan.exportSelection", null, null, saveSelection, false); 23 | // initMenuItem(subMenu, null, null, null, null); 24 | // initMenuItem(subMenu, "menu.scan.exportPreferences", null, null, null); 25 | // initMenuItem(subMenu, "menu.scan.importPreferences", null, null, null); 26 | if (!Platform.MAC_OS) { 27 | initMenuItem(this, null, null, null, null); 28 | initMenuItem(this, "menu.scan.quit", "Ctrl+Q", SWT.MOD1 | 'Q', quit); 29 | } 30 | } 31 | 32 | @Override 33 | public String getId() { 34 | return "menu.scan"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/gui/menu/ToolsMenu.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.menu; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.config.Platform; 5 | import net.azib.ipscan.gui.actions.ToolsActions; 6 | import org.eclipse.swt.SWT; 7 | import org.eclipse.swt.widgets.Menu; 8 | import org.eclipse.swt.widgets.MenuItem; 9 | import org.eclipse.swt.widgets.Shell; 10 | 11 | public class ToolsMenu extends AbstractMenu { 12 | public ToolsMenu(Shell parent, 13 | ToolsActions.Preferences preferences, 14 | ToolsActions.ChooseFetchers chooseFetchers, 15 | ToolsActions.ScanStatistics scanStatistics, 16 | ToolsActions.SelectAlive selectAlive, 17 | ToolsActions.SelectDead selectDead, 18 | ToolsActions.SelectWithPorts selectWithPorts, 19 | ToolsActions.SelectWithoutPorts selectWithoutPorts, 20 | ToolsActions.SelectInvert selectInvert) { 21 | super(parent); 22 | 23 | initMenuItem(this, "menu.tools.preferences", "Ctrl+Shift+P", SWT.MOD1 | (Platform.MAC_OS ? ',' : SWT.MOD2 | 'P'), preferences, true); 24 | initMenuItem(this, "menu.tools.fetchers", "Ctrl+Shift+O", SWT.MOD1 | SWT.MOD2 | (Platform.MAC_OS ? ',' : 'O'), chooseFetchers, true); 25 | initMenuItem(this, null, null, null, null); 26 | Menu selectMenu = initMenu(this, "menu.tools.select"); 27 | initMenuItem(this, "menu.tools.scanStatistics", "Ctrl+T", SWT.MOD1 | 'T', scanStatistics); 28 | 29 | initMenuItem(selectMenu, "menu.tools.select.alive", null, null, selectAlive, true); 30 | initMenuItem(selectMenu, "menu.tools.select.dead", null, null, selectDead, true); 31 | initMenuItem(selectMenu, "menu.tools.select.withPorts", null, null, selectWithPorts, true); 32 | initMenuItem(selectMenu, "menu.tools.select.withoutPorts", null, null, selectWithoutPorts, true); 33 | initMenuItem(selectMenu, null, null, null, null); 34 | initMenuItem(selectMenu, "menu.tools.select.invert", "Ctrl+I", SWT.MOD1 | 'I', selectInvert, true); 35 | } 36 | 37 | private static Menu initMenu(Menu menu, String label) { 38 | MenuItem menuItem = new MenuItem(menu, SWT.CASCADE); 39 | menuItem.setText(Labels.getLabel(label)); 40 | 41 | Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN); 42 | menuItem.setMenu(subMenu); 43 | 44 | return subMenu; 45 | } 46 | 47 | @Override 48 | public String getId() { 49 | return "menu.tools"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.util; 2 | 3 | import java.io.Closeable; 4 | import java.io.IOException; 5 | import java.net.DatagramSocket; 6 | import java.net.Socket; 7 | 8 | public class IOUtils { 9 | public static void closeQuietly(Socket socket) { 10 | if (socket != null) try { 11 | socket.close(); 12 | } 13 | catch (IOException ignore) { 14 | } 15 | } 16 | 17 | public static void closeQuietly(DatagramSocket socket) { 18 | if (socket != null) socket.close(); 19 | } 20 | 21 | public static void closeQuietly(Closeable closeable) { 22 | if (closeable != null) try { 23 | closeable.close(); 24 | } 25 | catch (IOException ignore) { 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/util/SequenceIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is a part of Angry IP Scanner source code, 3 | see http://www.angryip.org/ for more information. 4 | Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.util; 8 | 9 | import java.util.Iterator; 10 | 11 | /** 12 | * SequenceIterator - joins several iterators together to provide a seamless iteration. 13 | * 14 | * @author Anton Keks 15 | */ 16 | public class SequenceIterator implements Iterator { 17 | private Iterator[] iterators; 18 | int currentIndex = 0; 19 | 20 | public SequenceIterator(Iterator... iterators) { 21 | this.iterators = iterators; 22 | 23 | // check that last iterator is not empty (otherwise the code below won't work) 24 | if (!iterators[iterators.length-1].hasNext()) 25 | throw new IllegalArgumentException(); 26 | } 27 | 28 | public boolean hasNext() { 29 | // combined iterator has elements until the last iterator has them 30 | return iterators[iterators.length-1].hasNext(); 31 | } 32 | 33 | public E next() { 34 | // take the next iterator if current ran out of elements 35 | if (!iterators[currentIndex].hasNext()) 36 | currentIndex++; 37 | 38 | return iterators[currentIndex].next(); 39 | } 40 | 41 | public void remove() { 42 | iterators[currentIndex].remove(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/net/azib/ipscan/util/ThreadResourceBinder.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.util; 2 | 3 | import java.io.Closeable; 4 | import java.net.DatagramSocket; 5 | import java.net.Socket; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | import static net.azib.ipscan.util.IOUtils.closeQuietly; 10 | 11 | public class ThreadResourceBinder { 12 | private Map resources = new ConcurrentHashMap<>(256); 13 | 14 | public T bind(T resource) { 15 | resources.put(Thread.currentThread().getId(), resource); 16 | return resource; 17 | } 18 | 19 | public void close() { 20 | for (T resource : resources.values()) close(resource); 21 | resources.clear(); 22 | } 23 | 24 | private void close(T resource) { 25 | if (resource instanceof DatagramSocket) closeQuietly((DatagramSocket) resource); 26 | else if (resource instanceof Socket) closeQuietly((Socket) resource); 27 | else if (resource instanceof Closeable) closeQuietly((Closeable) resource); 28 | } 29 | 30 | public void closeAndUnbind(T resource) { 31 | close(resource); 32 | resources.remove(Thread.currentThread().getId()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/config/ComponentRegistryTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import net.azib.ipscan.di.Injector; 4 | import net.azib.ipscan.gui.MacApplicationMenu; 5 | import net.azib.ipscan.gui.MainWindow; 6 | import org.junit.Test; 7 | 8 | import static org.junit.Assert.assertNotNull; 9 | 10 | public class ComponentRegistryTest { 11 | @Test 12 | public void mainClassesCanBeCreated() throws Exception { 13 | Injector injector = new ComponentRegistry().init(); 14 | assertNotNull(injector.require(CommandLineProcessor.class)); 15 | assertNotNull(injector.require(MainWindow.class)); 16 | assertNotNull(injector.require(MacApplicationMenu.class)); 17 | } 18 | } -------------------------------------------------------------------------------- /test/net/azib/ipscan/config/ConfigTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | /** 9 | * @author Anton Keks 10 | */ 11 | public class ConfigTest { 12 | Config config = Config.getConfig(); 13 | 14 | @Test 15 | public void locale() { 16 | config.language = "et"; 17 | assertEquals(config.getLocale().toString(), "et"); 18 | } 19 | 20 | @Test 21 | public void localeWithRegion() { 22 | config.language = "pt_BR"; 23 | assertEquals(config.getLocale().toString(), "pt_BR"); 24 | } 25 | 26 | @Test 27 | public void testGetters() { 28 | assertNotNull(config.getPreferences()); 29 | assertNotNull(config.forScanner()); 30 | assertNotNull(config.forGUI()); 31 | assertNotNull(config.forFavorites()); 32 | assertNotNull(config.forOpeners()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/config/GUIConfigTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import net.azib.ipscan.fetchers.Fetcher; 4 | import org.eclipse.swt.graphics.Point; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import java.util.prefs.Preferences; 10 | 11 | import static org.junit.Assert.*; 12 | import static org.mockito.Mockito.mock; 13 | import static org.mockito.Mockito.when; 14 | 15 | /** 16 | * DimensionsConfigTest 17 | * 18 | * @author Anton Keks 19 | */ 20 | public class GUIConfigTest { 21 | 22 | private Preferences preferences; 23 | private GUIConfig config; 24 | 25 | @Before 26 | public void setUp() throws Exception { 27 | preferences = Preferences.userRoot().node("ipscan-test"); 28 | preferences.clear(); 29 | config = new GUIConfig(preferences); 30 | } 31 | 32 | @After 33 | public void tearDown() throws Exception { 34 | preferences.removeNode(); 35 | } 36 | 37 | @Test 38 | public void setMainWindowDimensions() throws Exception { 39 | Point size1 = new Point(2, 1); 40 | config.setMainWindowSize(size1, false); 41 | assertFalse(config.isMainWindowMaximized); 42 | assertEquals(size1, config.getMainWindowSize()); 43 | 44 | Point size2 = new Point(3, 4); 45 | config.setMainWindowSize(size2, true); 46 | assertTrue(config.isMainWindowMaximized); 47 | assertEquals(size1, config.getMainWindowSize()); 48 | } 49 | 50 | @Test 51 | public void store() throws Exception { 52 | config.setMainWindowSize(new Point(33, 44), false); 53 | config.store(); 54 | assertEquals(33, preferences.getInt("windowWidth", 0)); 55 | 56 | config.setMainWindowSize(new Point(55, 66), true); 57 | config.store(); 58 | assertEquals(33, preferences.getInt("windowWidth", 0)); 59 | } 60 | 61 | @Test 62 | public void columnWidths() throws Exception { 63 | Fetcher fetcher = mock(Fetcher.class); 64 | when(fetcher.getId()).thenReturn("fetcher.abc"); 65 | 66 | config.setColumnWidth(fetcher, 35); 67 | assertEquals(35, config.getColumnWidth(fetcher)); 68 | assertEquals(35, preferences.getInt("columnWidth." + fetcher.getId(), 0)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/config/LoggerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.config; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.logging.Logger; 6 | 7 | /** 8 | * @author Anton Keks 9 | */ 10 | public class LoggerFactoryTest extends TestCase { 11 | 12 | private static Logger staticLogger = LoggerFactory.getLogger(); 13 | 14 | public void testAutomaticNameInitialization() { 15 | assertEquals(getClass().getName(), staticLogger.getName()); 16 | assertEquals(getClass().getName(), LoggerFactory.getLogger().getName()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/PluginLoaderTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core; 2 | 3 | import net.azib.ipscan.fetchers.AbstractFetcher; 4 | import org.junit.Test; 5 | 6 | import java.io.File; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertTrue; 12 | 13 | public class PluginLoaderTest { 14 | PluginLoader loader = new PluginLoader(); 15 | List> container = new ArrayList<>(); 16 | 17 | @Test 18 | public void loadFromSystemProperty() { 19 | System.setProperty("ipscan.plugins", DummyFetcher.class.getName()); 20 | loader.loadPluginsSpecifiedInSystemProperties(container); 21 | assertEquals(DummyFetcher.class, container.get(0)); 22 | System.getProperties().remove("ipscan.plugins"); 23 | } 24 | 25 | @Test 26 | public void canFindClassLocation() { 27 | File file = loader.getClassLocation(getClass()); 28 | assertEquals("core", file.getParentFile().getName()); 29 | assertTrue(file.exists()); 30 | assertTrue(new File(file.getParent(), getClass().getSimpleName() + ".class").exists()); 31 | } 32 | 33 | @Test 34 | public void loadFromJarFile() { 35 | File pluginLocation = loader.getResourceLocation(getClass().getResource("test-plugin.jar")); 36 | loader.loadPluginJars(container, new File(pluginLocation.getParentFile(), "ipscan.jar")); 37 | 38 | Class plugin = container.get(0); 39 | assertEquals("test.TestPlugin", plugin.getName()); 40 | assertTrue(Plugin.class.isAssignableFrom(plugin)); 41 | } 42 | 43 | public static class DummyFetcher extends AbstractFetcher { 44 | public Object scan(ScanningSubject subject) { 45 | return "dummy"; 46 | } 47 | 48 | public String getId() { 49 | return "dummy"; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/PortIteratorTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | /** 9 | * PortIteratorTest 10 | * 11 | * @author Anton Keks 12 | */ 13 | public class PortIteratorTest { 14 | 15 | @Test 16 | public void testBasic() { 17 | assertEquals("1 2 3 5 7 ", iterateToString(new PortIterator("1,2,3,5,7"))); 18 | assertEquals("1 2 3 5 7 ", iterateToString(new PortIterator("1,\n2, 3,\t\t5,7"))); 19 | assertEquals("27 1 65535 ", iterateToString(new PortIterator("27, 1;65535"))); 20 | assertEquals("16 ", iterateToString(new PortIterator("16"))); 21 | assertEquals("", iterateToString(new PortIterator(""))); 22 | assertEquals("12 ", iterateToString(new PortIterator(" 12"))); 23 | assertEquals("12 ", iterateToString(new PortIterator("12, "))); 24 | } 25 | 26 | @Test 27 | public void testRange() { 28 | assertEquals("1 2 3 ", iterateToString(new PortIterator("1-3"))); 29 | assertEquals("65530 65531 65532 65533 65534 65535 ", iterateToString(new PortIterator("65530-65535"))); 30 | assertEquals("100 13 14 17 18 19 20 ", iterateToString(new PortIterator("100,13-14,17-20"))); 31 | } 32 | 33 | @Test 34 | public void testSize() throws Exception { 35 | assertEquals(0, new PortIterator("").size()); 36 | assertEquals(1, new PortIterator("80").size()); 37 | assertEquals(5, new PortIterator("5,10-12,1").size()); 38 | assertEquals(65000, new PortIterator("1-65000").size()); 39 | } 40 | 41 | @Test 42 | public void testCopy() { 43 | assertNotNull(new PortIterator("1").copy()); 44 | } 45 | 46 | @Test(expected=NumberFormatException.class) 47 | public void testBrokenNumber() throws Exception { 48 | new PortIterator("foo"); 49 | } 50 | 51 | @Test(expected=NumberFormatException.class) 52 | public void testTooLarge() throws Exception { 53 | new PortIterator("65536"); 54 | } 55 | 56 | @Test(expected=NumberFormatException.class) 57 | public void testZero() throws Exception { 58 | new PortIterator("1,2,0,3"); 59 | } 60 | 61 | @Test(expected=NumberFormatException.class) 62 | public void testNegative() throws Exception { 63 | new PortIterator("-3"); 64 | } 65 | 66 | private static String iterateToString(PortIterator iterator) { 67 | StringBuffer sb = new StringBuffer(64); 68 | while (iterator.hasNext()) { 69 | sb.append(iterator.next()).append(' '); 70 | } 71 | return sb.toString(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/ARPPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | public class ARPPingerTest extends AbstractPingerTest { 4 | public ARPPingerTest() throws Exception { 5 | super(ARPPinger.class); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/AbstractPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.config.ComponentRegistry; 4 | import net.azib.ipscan.core.ScanningSubject; 5 | import net.azib.ipscan.di.Injector; 6 | import net.azib.ipscan.util.InetAddressUtils; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | import java.net.InetAddress; 11 | import java.net.InterfaceAddress; 12 | 13 | import static org.junit.Assert.*; 14 | 15 | abstract class AbstractPingerTest { 16 | Pinger pinger; 17 | 18 | AbstractPingerTest(Class pingerClass) throws Exception { 19 | Injector injector = new ComponentRegistry().init(false); 20 | this.pinger = injector.require(pingerClass); 21 | } 22 | 23 | @Test 24 | public void pingAlive() throws IOException { 25 | InterfaceAddress ifAddr = InetAddressUtils.getLocalInterface(); 26 | PingResult result = pinger.ping(new ScanningSubject(ifAddr.getAddress()), 2); 27 | assertTrue(result.isAlive()); 28 | assertEquals(2, result.getPacketCount()); 29 | assertEquals(2, result.getReplyCount()); 30 | assertTrue(result.getAverageTime() <= 10); 31 | assertTrue(result.getTTL() >= 0); 32 | } 33 | 34 | @Test 35 | public void pingDead() throws IOException { 36 | PingResult result = pinger.ping(new ScanningSubject(InetAddress.getByName("192.168.99.253")), 1); 37 | assertFalse(result.isAlive()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/CombinedUnprivilegedPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | public class CombinedUnprivilegedPingerTest extends AbstractPingerTest { 4 | public CombinedUnprivilegedPingerTest() throws Exception { 5 | super(CombinedUnprivilegedPinger.class); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/JavaPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | public class JavaPingerTest extends AbstractPingerTest { 4 | public JavaPingerTest() throws Exception { 5 | super(JavaPinger.class); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/PingerRegistryTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.config.ComponentRegistry; 4 | import net.azib.ipscan.config.Config; 5 | import net.azib.ipscan.config.Labels; 6 | import net.azib.ipscan.config.ScannerConfig; 7 | import net.azib.ipscan.core.ScanningSubject; 8 | import net.azib.ipscan.fetchers.FetcherException; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class PingerRegistryTest { 15 | ScannerConfig config = Config.getConfig().forScanner(); 16 | PingerRegistry registry; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | registry = new PingerRegistry(config, new ComponentRegistry().init(false)); 21 | } 22 | 23 | @Test 24 | public void getRegisteredNames() { 25 | String[] names = registry.getRegisteredNames(); 26 | assertNotNull(names); 27 | for (String name : names) { 28 | assertNotNull(Labels.getLabel(name)); 29 | } 30 | } 31 | 32 | @Test 33 | public void createPinger() throws Exception { 34 | String[] names = registry.getRegisteredNames(); 35 | for (String name : names) { 36 | try { 37 | Pinger pinger = registry.createPinger(name, 0); 38 | pinger.close(); 39 | } 40 | catch (FetcherException e) { 41 | // ignore in case RawSockets cannot be initialized 42 | // under current conditions 43 | assertEquals("pingerCreateFailure", e.getMessage()); 44 | } 45 | } 46 | } 47 | 48 | @Test 49 | public void createSelectedPinger() { 50 | config.selectedPinger = "pinger.tcp"; 51 | assertTrue(registry.createPinger(false) instanceof TCPPinger); 52 | } 53 | 54 | @Test 55 | public void checkBackwardCompatibleCreation() { 56 | assertTrue(registry.createPinger(PingerDefaultConstructor.class, 0) instanceof PingerDefaultConstructor); 57 | assertTrue(registry.createPinger(PingerWithTimeoutConstructor.class, 0) instanceof PingerWithTimeoutConstructor); 58 | } 59 | 60 | abstract static class AbstractTestPinger implements Pinger { 61 | @Override public PingResult ping(ScanningSubject subject, int count) { 62 | return null; 63 | } 64 | } 65 | 66 | public static class PingerDefaultConstructor extends AbstractTestPinger { } 67 | 68 | static class PingerWithTimeoutConstructor extends AbstractTestPinger { 69 | public PingerWithTimeoutConstructor(int value) {} 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/TCPPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | public class TCPPingerTest extends AbstractPingerTest { 4 | public TCPPingerTest() throws Exception { 5 | super(TCPPinger.class); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/UDPPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.junit.Assume.assumeTrue; 9 | 10 | public class UDPPingerTest extends AbstractPingerTest { 11 | public UDPPingerTest() throws Exception { 12 | super(UDPPinger.class); 13 | } 14 | 15 | @Test @Override 16 | public void pingAlive() throws IOException { 17 | assumeTrue(Platform.LINUX); 18 | super.pingAlive(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/net/WindowsPingerTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.net; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import org.junit.BeforeClass; 5 | 6 | import static org.junit.Assume.assumeTrue; 7 | 8 | public class WindowsPingerTest extends AbstractPingerTest { 9 | public WindowsPingerTest() throws Exception { 10 | super(WindowsPinger.class); 11 | } 12 | 13 | @BeforeClass 14 | public static void beforeClass() { 15 | assumeTrue(Platform.WINDOWS); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/state/ScanningStateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.state; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import org.junit.Test; 12 | 13 | /** 14 | * ScanningStateTest 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class ScanningStateTest { 19 | 20 | @Test 21 | public void testNext() throws Exception { 22 | assertEquals(ScanningState.STARTING, ScanningState.IDLE.next()); 23 | assertEquals(ScanningState.SCANNING, ScanningState.STARTING.next()); 24 | assertEquals(ScanningState.SCANNING, ScanningState.RESTARTING.next()); 25 | assertEquals(ScanningState.STOPPING, ScanningState.SCANNING.next()); 26 | assertEquals(ScanningState.KILLING, ScanningState.STOPPING.next()); 27 | assertNull(ScanningState.KILLING.next()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/test-plugin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angryip/ipscan/c7ce1d4bbdcca985db8919ba2e6514dec0f36b1f/test/net/azib/ipscan/core/test-plugin.jar -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/values/InetAddressHolderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.core.values; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import java.net.InetAddress; 12 | 13 | import org.junit.Test; 14 | 15 | /** 16 | * InetAddressValueTest 17 | * 18 | * @author Anton Keks 19 | */ 20 | public class InetAddressHolderTest { 21 | @Test 22 | public void testToString() throws Exception { 23 | InetAddressHolder av = new InetAddressHolder(InetAddress.getLocalHost()); 24 | assertEquals(InetAddress.getLocalHost().getHostAddress(), av.toString()); 25 | } 26 | 27 | @Test 28 | public void testCompareTo() throws Exception { 29 | InetAddressHolder av2 = new InetAddressHolder(InetAddress.getByName("192.168.0.2")); 30 | InetAddressHolder av10 = new InetAddressHolder(InetAddress.getByName("192.168.0.10")); 31 | InetAddressHolder av127 = new InetAddressHolder(InetAddress.getByName("192.168.0.127")); 32 | InetAddressHolder av253 = new InetAddressHolder(InetAddress.getByName("192.168.0.253")); 33 | assertEquals(-1, av2.compareTo(av10)); 34 | assertEquals(1, av10.compareTo(av2)); 35 | assertEquals(0, av2.compareTo(av2)); 36 | assertEquals(-1, av10.compareTo(av253)); 37 | assertEquals(-1, av127.compareTo(av253)); 38 | assertEquals(1, av253.compareTo(av127)); 39 | assertEquals(1, av253.compareTo(av2)); 40 | assertEquals(0, av253.compareTo(av253)); 41 | } 42 | 43 | @Test 44 | public void testEqualsHashCode() throws Exception { 45 | InetAddressHolder av1 = new InetAddressHolder(InetAddress.getByName("192.168.0.2")); 46 | InetAddressHolder av2 = new InetAddressHolder(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, 0, 2})); 47 | assertEquals(av1, av2); 48 | assertEquals(av1.hashCode(), av2.hashCode()); 49 | assertFalse(av1.equals(null)); 50 | assertFalse(av1.equals("")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/values/IntegerWithUnitTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.values; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | /** 9 | * IntegerWithUnitTest 10 | * 11 | * @author Anton Keks 12 | */ 13 | public class IntegerWithUnitTest { 14 | 15 | @Test 16 | public void testIntValue() throws Exception { 17 | assertEquals(0, new IntegerWithUnit(0, "a").intValue()); 18 | assertEquals(-1, new IntegerWithUnit(-1, "a").intValue()); 19 | assertEquals(Integer.MAX_VALUE, new IntegerWithUnit(Integer.MAX_VALUE, "a").intValue()); 20 | } 21 | 22 | @Test 23 | public void testToString() throws Exception { 24 | assertEquals("151" + Labels.getLabel("unit.ms"), new IntegerWithUnit(151, "ms").toString()); 25 | } 26 | 27 | @Test 28 | public void testEquals() throws Exception { 29 | assertTrue(new IntegerWithUnit(666, null).equals(new IntegerWithUnit(666, null))); 30 | assertTrue(new IntegerWithUnit(42, "a").equals(new IntegerWithUnit(42, "b"))); 31 | assertFalse(new IntegerWithUnit(0, null).equals(null)); 32 | assertFalse(new IntegerWithUnit(42, "a").equals(new IntegerWithUnit(43, "a"))); 33 | } 34 | 35 | @Test 36 | public void testHashCode() throws Exception { 37 | assertEquals(3, new IntegerWithUnit(3, null).hashCode()); 38 | assertEquals(-31, new IntegerWithUnit(-31, null).hashCode()); 39 | } 40 | 41 | @Test 42 | public void testCompareTo() throws Exception { 43 | assertTrue(Comparable.class.isAssignableFrom(IntegerWithUnit.class)); 44 | assertEquals(0, new IntegerWithUnit(1, null).compareTo(new IntegerWithUnit(1, null))); 45 | assertEquals(1, new IntegerWithUnit(123456789, null).compareTo(new IntegerWithUnit(123456, null))); 46 | assertEquals(-1, new IntegerWithUnit(12, null).compareTo(new IntegerWithUnit(123456, null))); 47 | assertEquals(1, new IntegerWithUnit(12, null).compareTo(null)); 48 | IntegerWithUnit instance = new IntegerWithUnit(211082, null); 49 | assertEquals(0, instance.compareTo(instance)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/values/NotAvailableTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.values; 2 | 3 | import net.azib.ipscan.config.Config; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | /** 10 | * NotAvailableValueTest 11 | * 12 | * @author Anton Keks 13 | */ 14 | public class NotAvailableTest { 15 | 16 | @Test 17 | public void testEquals() throws Exception { 18 | assertEquals(NotAvailable.VALUE, NotAvailable.VALUE); 19 | } 20 | 21 | @Test 22 | public void testToString() throws Exception { 23 | assertEquals(Config.getConfig().forScanner().notAvailableText, NotAvailable.VALUE.toString()); 24 | } 25 | 26 | @Test 27 | public void testCompareTo() throws Exception { 28 | assertTrue(Comparable.class.isAssignableFrom(NotAvailable.class)); 29 | assertEquals(0, NotAvailable.VALUE.compareTo(NotAvailable.VALUE)); 30 | Empty.setSortDirection(true); 31 | assertEquals(1, NotAvailable.VALUE.compareTo("Hello")); 32 | assertEquals(1, NotAvailable.VALUE.compareTo(null)); 33 | Empty.setSortDirection(false); 34 | assertEquals(-1, NotAvailable.VALUE.compareTo("Hello")); 35 | Empty.setSortDirection(true); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/values/NotScannedTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.core.values; 2 | 3 | import net.azib.ipscan.config.Config; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | /** 10 | * NotScannedValueTest 11 | * 12 | * @author Anton Keks 13 | */ 14 | public class NotScannedTest { 15 | 16 | @Test 17 | public void testEquals() throws Exception { 18 | assertEquals(NotScanned.VALUE, NotScanned.VALUE); 19 | } 20 | 21 | @Test 22 | public void testToString() throws Exception { 23 | assertEquals(Config.getConfig().forScanner().notScannedText, NotScanned.VALUE.toString()); 24 | } 25 | 26 | @Test 27 | public void testCompareTo() throws Exception { 28 | assertTrue(Comparable.class.isAssignableFrom(NotScanned.class)); 29 | assertEquals(0, NotScanned.VALUE.compareTo(NotScanned.VALUE)); 30 | Empty.setSortDirection(true); 31 | assertEquals(1, NotScanned.VALUE.compareTo("Hello")); 32 | assertEquals(1, NotScanned.VALUE.compareTo(null)); 33 | Empty.setSortDirection(false); 34 | assertEquals(-1, NotScanned.VALUE.compareTo("Hello")); 35 | Empty.setSortDirection(true); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/core/values/NumericRangeListTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.core.values; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.Arrays; 11 | import java.util.Collections; 12 | import java.util.TreeSet; 13 | 14 | import org.junit.Test; 15 | 16 | /** 17 | * @author Anton Keks 18 | */ 19 | public class NumericRangeListTest { 20 | 21 | @Test 22 | public void testToString() { 23 | assertEquals("", new NumericRangeList(Collections.emptyList(), true).toString()); 24 | assertEquals("1", new NumericRangeList(Arrays.asList(1), true).toString()); 25 | assertEquals("1,2", new NumericRangeList(Arrays.asList(1, 2), true).toString()); 26 | assertEquals("1-3", new NumericRangeList(Arrays.asList(1, 2, 3), true).toString()); 27 | assertEquals("1-3", new NumericRangeList(new TreeSet(Arrays.asList(2, 3, 1)), true).toString()); 28 | assertEquals("1,2,3", new NumericRangeList(Arrays.asList(1, 2, 3), false).toString()); 29 | assertEquals("1,5,6,15", new NumericRangeList(Arrays.asList(1, 5, 6, 15), true).toString()); 30 | assertEquals("1,5-8,15", new NumericRangeList(Arrays.asList(1, 5, 6, 7, 8, 15), true).toString()); 31 | assertEquals("103,85,89,1", new NumericRangeList(Arrays.asList(103, 85, 89, 1), true).toString()); 32 | } 33 | 34 | @Test 35 | public void testCompateTo() throws Exception { 36 | assertTrue(new NumericRangeList(Arrays.asList(22), false).compareTo(new NumericRangeList(Arrays.asList(80), false)) < 0); 37 | assertTrue(new NumericRangeList(Arrays.asList(80), false).compareTo(new NumericRangeList(Arrays.asList(22), false)) > 0); 38 | assertTrue(new NumericRangeList(Arrays.asList(255), false).compareTo(new NumericRangeList(Arrays.asList(255), false)) == 0); 39 | assertTrue(new NumericRangeList(Arrays.asList(1, 2), false).compareTo(new NumericRangeList(Arrays.asList(8080), false)) > 0); 40 | assertTrue(new NumericRangeList(Arrays.asList(22, 25, 27, 28), false).compareTo(new NumericRangeList(Arrays.asList(22, 25, 26, 300), false)) > 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/di/InjectorTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.di; 2 | 3 | import org.junit.Test; 4 | 5 | import java.time.LocalDate; 6 | import java.time.LocalDateTime; 7 | import java.time.LocalTime; 8 | import java.time.temporal.Temporal; 9 | import java.util.List; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertNotNull; 13 | 14 | public class InjectorTest { 15 | private Injector injector = new Injector(); 16 | 17 | @Test 18 | public void require() { 19 | assertNotNull(injector.require(Dummy.class)); 20 | assertNotNull(injector.require(WithDeps.class).dummy); 21 | } 22 | 23 | @Test 24 | public void namedRequire() { 25 | injector.register(String.class, "mega-name"); 26 | assertEquals("mega-name", injector.require(WithNamedDeps.class).name); 27 | } 28 | 29 | @Test 30 | public void requireAll() { 31 | injector.register(LocalDate.class, LocalDate.now()); 32 | injector.register(LocalTime.class, LocalTime.now()); 33 | injector.register(LocalDateTime.class, LocalDateTime.now()); 34 | 35 | List temporals = injector.requireAll(Temporal.class); 36 | assertEquals(3, temporals.size()); 37 | assertEquals(temporals, injector.require(WithListDeps.class).list); 38 | } 39 | 40 | static class Dummy { 41 | public Dummy() {} 42 | } 43 | 44 | static class WithDeps { 45 | Dummy dummy; 46 | public WithDeps() {} 47 | public WithDeps(Dummy dummy) { this.dummy = dummy; } 48 | } 49 | 50 | static class WithNamedDeps { 51 | String name; 52 | public WithNamedDeps(Dummy dummy, String name) { 53 | this.name = name; 54 | } 55 | } 56 | 57 | static class WithListDeps { 58 | List list; 59 | public WithListDeps(List list, Dummy dummy) { 60 | this.list = list; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/exporters/CSVExporterTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.exporters; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * CSV Exporter Test 12 | * 13 | * @author Anton Keks 14 | */ 15 | public class CSVExporterTest extends AbstractExporterTestCase { 16 | 17 | protected Exporter createExporter() { 18 | return new CSVExporter(); 19 | } 20 | 21 | @Test 22 | public void testCSVSafeString() { 23 | assertEquals(".a.bb.c.d.", ((CSVExporter)exporter).csvSafeString(",a,bb,c,d,")); 24 | assertEquals("", ((CSVExporter)exporter).csvSafeString("")); 25 | assertEquals("uuuuhha;", ((CSVExporter)exporter).csvSafeString("uuuuhha;")); 26 | assertEquals("", ((CSVExporter)exporter).csvSafeString(null)); 27 | assertEquals("123", ((CSVExporter)exporter).csvSafeString(123L)); 28 | } 29 | 30 | @Test 31 | public void testFetchersWithoutAppend() throws IOException { 32 | exporter.start(outputStream, null); 33 | exporter.setFetchers(new String[] {"fet1", "hello2", "Mega Fetcher", "oops, comma here"}); 34 | exporter.end(); 35 | assertContains("fet1"); 36 | assertContains("Mega Fetcher"); 37 | assertContains("oops. comma here"); 38 | } 39 | 40 | @Test 41 | public void testNextAddressResults() throws IOException { 42 | exporter.start(outputStream, null); 43 | exporter.setFetchers(new String[] {"fet1", "hello2"}); 44 | exporter.nextAddressResults(new Object[] {InetAddress.getLocalHost(), "oops, comma"}); 45 | exporter.end(); 46 | assertContains("oops. comma"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/exporters/ExporterRegistryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | package net.azib.ipscan.exporters; 5 | 6 | import org.junit.Test; 7 | 8 | import java.util.Arrays; 9 | import java.util.Iterator; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * ExporterRegistryTest 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class ExporterRegistryTest { 19 | 20 | private ExporterRegistry exporterRegistry = new ExporterRegistry(Arrays.asList(new TXTExporter(), new CSVExporter())); 21 | 22 | @Test 23 | public void testIterator() { 24 | for (Iterator i = exporterRegistry.iterator(); i.hasNext(); ) { 25 | Exporter exporter = (Exporter) i.next(); 26 | assertNotNull(exporter); 27 | assertNotNull(exporter.getFilenameExtension()); 28 | } 29 | } 30 | 31 | @Test 32 | public void testCreate() { 33 | Exporter exporter; 34 | 35 | exporter = exporterRegistry.createExporter("aa.abc." + new TXTExporter().getFilenameExtension()); 36 | assertTrue(exporter instanceof TXTExporter); 37 | 38 | exporter = exporterRegistry.createExporter("/tmp/foo/megafile." + new TXTExporter().getFilenameExtension()); 39 | assertTrue(exporter instanceof TXTExporter); 40 | } 41 | 42 | @Test 43 | public void testCreateFailed() { 44 | try { 45 | exporterRegistry.createExporter("noextension"); 46 | fail(); 47 | } 48 | catch (ExporterException e) { 49 | assertEquals("exporter.unknown", e.getMessage()); 50 | } 51 | 52 | try { 53 | exporterRegistry.createExporter("unknown.extension"); 54 | fail(); 55 | } 56 | catch (ExporterException e) { 57 | assertEquals("exporter.unknown", e.getMessage()); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/exporters/import-broken.txt: -------------------------------------------------------------------------------- 1 | Scanned 192.168.0.0 - 192.168.0.255 2 | 3 | IP Ping Hostname Ports Comments MAC Vendor MAC Address 4 | 5 | 192.168.0.1 3 ms router.local 80 [n/a] CiscoSpv E4:48:C7:EE:28:C2 6 | 192.168.0.3 1 ms accesspoint.local 22,80 [n/a] Tp-LinkT 30:B5:C2:B9:B9:4E 7 | 8 | 192.168.0.2 0 ms nas.local 22,80,443 [n/a] Synology 00:11:32:0E:92:BC 9 | 192.168.0.13 0 ms aziber.local 22 [n/a] IntelCor 7C:7A:91:15:8C:6D 10 | 192.168.0.10 2 ms [n/a] [n/a] [n/a] Azurewav 6C:AD:F8:74:CB:0F 11 | 12 | 192.168.0.15 5 ms [n/a] [n/a] [n/a] IntekDig 30:EB:25:00:A0:F8 13 | Blah blah 14 | 192.168.0.18 60 ms [n/a] [n/a] [n/a] LgElectr 34:FC:EF:DC:29:2B 15 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/exporters/import.txt: -------------------------------------------------------------------------------- 1 | Generated by Angry IP Scanner current 2 | https://angryip.org 3 | 4 | Scanned 192.168.0.0 - 192.168.0.255 5 | 01-Sep-2015 23:47:27 6 | 7 | IP Ping Hostname Ports Comments MAC Vendor MAC Address 8 | 192.168.0.1 3 ms router.local 80 [n/a] CiscoSpv E4:48:C7:EE:28:C2 9 | 192.168.0.3 1 ms accesspoint.local 22,80 [n/a] Tp-LinkT 30:B5:C2:B9:B9:4E 10 | 192.168.0.2 0 ms nas.local 22,80,443 [n/a] Synology 00:11:32:0E:92:BC 11 | 192.168.0.13 0 ms aziber.local 22 [n/a] IntelCor 7C:7A:91:15:8C:6D 12 | 192.168.0.10 2 ms [n/a] [n/a] [n/a] Azurewav 6C:AD:F8:74:CB:0F 13 | 192.168.0.15 5 ms [n/a] [n/a] [n/a] IntekDig 30:EB:25:00:A0:F8 14 | 192.168.0.18 60 ms [n/a] [n/a] [n/a] LgElectr 34:FC:EF:DC:29:2B 15 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/feeders/FeederTestUtils.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.feeders; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | /** 9 | * FeederTestUtils 10 | * 11 | * @author Anton Keks 12 | */ 13 | public class FeederTestUtils { 14 | public static void assertFeederException(String message, FeederException e) { 15 | // assert that the message is correct 16 | assertEquals(message, e.getMessage()); 17 | // check that corresponding label exists 18 | assertNotNull(Labels.getLabel("exception.FeederException." + message)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/feeders/RescanFeederTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.feeders; 8 | 9 | import net.azib.ipscan.config.Labels; 10 | import net.azib.ipscan.core.ScanningSubject; 11 | import org.junit.Test; 12 | 13 | import static org.junit.Assert.*; 14 | import static org.mockito.Mockito.*; 15 | 16 | /** 17 | * RescanFeederTest 18 | * 19 | * @author Anton Keks 20 | */ 21 | public class RescanFeederTest { 22 | 23 | private Feeder feeder; 24 | 25 | @Test(expected=IllegalArgumentException.class) 26 | public void testEmpty() throws Exception { 27 | new RescanFeeder(null); 28 | } 29 | 30 | @Test 31 | public void testDelegatedMethods() { 32 | feeder = new RescanFeeder(mockFeeder(), "123"); 33 | assertEquals("SomeInfo", feeder.getInfo()); 34 | assertEquals("someLabel", feeder.getId()); 35 | assertEquals(Labels.getLabel("feeder.rescan.of") + "someName", feeder.getName()); 36 | } 37 | 38 | @Test 39 | public void addresses() { 40 | feeder = new RescanFeeder(mockFeeder(), "127.0.0.15", "127.0.1.35", "127.0.2.2"); 41 | 42 | assertTrue(feeder.hasNext()); 43 | assertEquals(0, feeder.percentageComplete()); 44 | assertEquals("127.0.0.15", feeder.next().getAddress().getHostAddress()); 45 | 46 | assertTrue(feeder.hasNext()); 47 | assertEquals(33, feeder.percentageComplete()); 48 | assertEquals("127.0.1.35", feeder.next().getAddress().getHostAddress()); 49 | 50 | assertTrue(feeder.hasNext()); 51 | assertEquals(66, feeder.percentageComplete()); 52 | assertEquals("127.0.2.2", feeder.next().getAddress().getHostAddress()); 53 | 54 | assertFalse(feeder.hasNext()); 55 | assertEquals(100, feeder.percentageComplete()); 56 | } 57 | 58 | private Feeder mockFeeder() { 59 | Feeder feeder = mock(Feeder.class); 60 | when(feeder.getInfo()).thenReturn("SomeInfo"); 61 | when(feeder.getId()).thenReturn("someLabel"); 62 | when(feeder.getName()).thenReturn("someName"); 63 | when(feeder.subject(any())).thenAnswer(i -> new ScanningSubject(i.getArgument(0))); 64 | return feeder; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/AbstractFetcherTestCase.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | /** 9 | * TestCase for Fetchers. 10 | * It contains initialization and generic tests for any Fetcher. 11 | * 12 | * @author Anton Keks 13 | */ 14 | public abstract class AbstractFetcherTestCase { 15 | 16 | Fetcher fetcher; 17 | 18 | @Before 19 | public abstract void setUp() throws Exception; 20 | 21 | @Test 22 | public void testId() { 23 | assertNotNull(fetcher.getId()); 24 | } 25 | 26 | @Test 27 | public void testName() { 28 | assertNotNull(fetcher.getName()); 29 | } 30 | 31 | @Test 32 | public void testFullName() { 33 | assertNotNull(fetcher.getFullName()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/HostnameFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import java.net.InetAddress; 8 | import java.net.UnknownHostException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertNull; 12 | 13 | /** 14 | * HostnameFetcherTest 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class HostnameFetcherTest extends AbstractFetcherTestCase { 19 | 20 | @Before 21 | public void setUp() throws Exception { 22 | fetcher = new HostnameFetcher(); 23 | } 24 | 25 | @Test 26 | public void resolveForReal() throws UnknownHostException { 27 | // Some of these tests are run inside of if's to prevent their failing on certain network configurations 28 | if (!InetAddress.getLocalHost().getCanonicalHostName().equals(InetAddress.getLocalHost().getHostAddress())) 29 | assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()))); 30 | 31 | try { 32 | InetAddress address = InetAddress.getByName("era.ee"); 33 | assertEquals("ns.era.ee", fetcher.scan(new ScanningSubject(address))); 34 | } 35 | catch (UnknownHostException e) { /* ignore - test is running in off-line environment */ } 36 | 37 | InetAddress inexistentAddress = InetAddress.getByName("192.168.253.253"); 38 | if (inexistentAddress.getHostName().equals("192.168.253.253")) 39 | assertNull(fetcher.scan(new ScanningSubject(inexistentAddress))); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/IPFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import java.net.InetAddress; 8 | import java.net.UnknownHostException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | /** 13 | * IPFetcherTest 14 | * 15 | * @author Anton Keks 16 | */ 17 | public class IPFetcherTest extends AbstractFetcherTestCase { 18 | 19 | @Before 20 | public void setUp() throws Exception { 21 | fetcher = new IPFetcher(); 22 | } 23 | 24 | @Test 25 | public void testScan() throws UnknownHostException { 26 | assertEquals(InetAddress.getLocalHost().getHostAddress(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost())).toString()); 27 | assertEquals("255.255.255.255", fetcher.scan(new ScanningSubject(InetAddress.getByName("255.255.255.255"))).toString()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/LinuxMACFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.Platform; 4 | import net.azib.ipscan.core.ScanningSubject; 5 | import org.junit.Test; 6 | 7 | import static net.azib.ipscan.util.InetAddressUtils.getLocalInterface; 8 | import static org.junit.Assert.assertEquals; 9 | import static org.junit.Assume.assumeTrue; 10 | 11 | public class LinuxMACFetcherTest { 12 | @Test 13 | public void resolve() { 14 | assumeTrue(Platform.LINUX); 15 | ScanningSubject subject = new ScanningSubject(getLocalInterface().getAddress()); 16 | assertEquals(17, new LinuxMACFetcher().resolveMAC(subject).length()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/MACFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import org.junit.Test; 5 | 6 | import java.net.InetAddress; 7 | import java.net.UnknownHostException; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class MACFetcherTest { 12 | private MACFetcher fetcher = new MACFetcher() { 13 | @Override protected String resolveMAC(ScanningSubject subject) { 14 | return "00:01:02:03:04:05"; 15 | } 16 | }; 17 | 18 | @Test 19 | public void extractMAC() { 20 | assertEquals("E4:48:C7:EE:28:C2", fetcher.extractMAC("? (192.168.0.1) at e4:48:c7:ee:28:c2 [ether] on wlan0")); 21 | } 22 | 23 | @Test 24 | public void extractMACAddsLeadingZeroesOnOsX() { 25 | assertEquals("04:48:07:EE:28:02", fetcher.extractMAC("? (192.168.0.1) at 4:48:7:ee:28:2 [ether] on wlan0")); 26 | assertEquals("C4:2C:03:08:1E:89", fetcher.extractMAC("? (10.10.10.96) at c4:2c:3:8:1e:89 on en0 ifscope permanent [ethernet]")); 27 | } 28 | 29 | @Test 30 | public void bytesToMAC() { 31 | assertEquals("", MACFetcher.bytesToMAC(new byte[0])); 32 | assertEquals("00:01:02:0D", MACFetcher.bytesToMAC(new byte[] {0, 1, 2, 13})); 33 | } 34 | 35 | @Test 36 | public void redefinedSeparator() throws UnknownHostException { 37 | ScanningSubject subject = new ScanningSubject(InetAddress.getLocalHost()); 38 | fetcher.separator = ":"; 39 | assertEquals("00:01:02:03:04:05", fetcher.scan(subject)); 40 | assertEquals("00:01:02:03:04:05", subject.getParameter(MACFetcher.ID)); 41 | fetcher.separator = "-"; 42 | assertEquals("00-01-02-03-04-05", fetcher.scan(subject)); 43 | assertEquals("00:01:02:03:04:05", subject.getParameter(MACFetcher.ID)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/MACVendorFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.core.ScanningSubject; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class MACVendorFetcherTest { 9 | @Test 10 | public void findMACVendor() { 11 | MACFetcher macFetcher = new MACFetcher() { 12 | @Override protected String resolveMAC(ScanningSubject subject) { return null; } 13 | }; 14 | MACVendorFetcher fetcher = new MACVendorFetcher(macFetcher); 15 | fetcher.init(); 16 | assertEquals("XEROX", fetcher.findMACVendor("00:00:01:00:00:00")); 17 | assertEquals("Nokia", fetcher.findMACVendor("FC:E5:57:11:22:33")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/PacketLossFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.Config; 4 | import org.junit.Before; 5 | 6 | public class PacketLossFetcherTest extends AbstractFetcherTestCase { 7 | @Before 8 | public void setUp() { 9 | fetcher = new PacketLossFetcher(null, Config.getConfig().forScanner()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/PingFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.Config; 4 | import org.junit.Before; 5 | 6 | /** 7 | * PingFetcherTest 8 | * 9 | * @author Anton Keks 10 | */ 11 | public class PingFetcherTest extends AbstractFetcherTestCase { 12 | 13 | @Before 14 | public void setUp() throws Exception { 15 | fetcher = new PingFetcher(null, Config.getConfig().forScanner()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/fetchers/PingTTLFetcherTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.fetchers; 2 | 3 | import net.azib.ipscan.config.Config; 4 | import org.junit.Before; 5 | 6 | /** 7 | * PingTTLFetcherTest 8 | * 9 | * @author Anton Keks 10 | */ 11 | public class PingTTLFetcherTest extends AbstractFetcherTestCase { 12 | 13 | @Before 14 | public void setUp() throws Exception { 15 | fetcher = new PingTTLFetcher(null, Config.getConfig().forScanner()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/GUITest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.feeders.FeederException; 5 | import org.junit.Test; 6 | 7 | import java.util.logging.Handler; 8 | import java.util.logging.LogRecord; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertTrue; 12 | 13 | public class GUITest { 14 | @Test 15 | public void getLocalizedMessage() { 16 | // unknown exception 17 | final boolean[] wasStackTraceLogged = {false}; 18 | Throwable e = new Exception("hello, test!"); 19 | GUI.LOG.setUseParentHandlers(false); 20 | GUI.LOG.addHandler(new Handler() { 21 | public void close() throws SecurityException { 22 | } 23 | public void flush() { 24 | } 25 | public void publish(LogRecord record) { 26 | wasStackTraceLogged[0] = true; 27 | } 28 | }); 29 | assertEquals(e.toString(), GUI.getLocalizedMessage(e)); 30 | assertTrue(wasStackTraceLogged[0]); 31 | 32 | // localized exception 33 | assertEquals(Labels.getLabel("exception.FeederException.malformedIP"), 34 | GUI.getLocalizedMessage(new FeederException("malformedIP"))); 35 | 36 | // message-less localized exception 37 | assertEquals(Labels.getLabel("exception.OutOfMemoryError"), 38 | GUI.getLocalizedMessage(new OutOfMemoryError())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/InputDialogTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import org.eclipse.swt.SWT; 12 | import org.eclipse.swt.layout.FormData; 13 | import org.eclipse.swt.widgets.Event; 14 | import org.junit.After; 15 | import org.junit.Test; 16 | 17 | /** 18 | * InputDialogTest 19 | * 20 | * @author Anton Keks 21 | */ 22 | public class InputDialogTest { 23 | 24 | private InputDialog dialog = new InputDialog("title", "msg") { 25 | @Override 26 | public void open() { 27 | // do not open anything in tests 28 | } 29 | }; 30 | 31 | @After 32 | public void dispose() { 33 | if (!dialog.text.isDisposed()) 34 | dialog.text.getShell().dispose(); 35 | } 36 | 37 | @Test 38 | public void titleAndMessageDisplayed() throws Exception { 39 | assertEquals("msg", dialog.messageLabel.getText()); 40 | assertEquals("title", dialog.messageLabel.getShell().getText()); 41 | } 42 | 43 | @Test 44 | public void defaultText() throws Exception { 45 | dialog.open("hello"); 46 | assertEquals("hello", dialog.text.getSelectionText()); 47 | } 48 | 49 | @Test 50 | public void nullText() throws Exception { 51 | dialog.open(null); 52 | assertEquals("", dialog.text.getText()); 53 | assertTrue(((FormData)dialog.text.getLayoutData()).width > 200); 54 | } 55 | 56 | @Test 57 | public void openReturnsEnteredText() throws Exception { 58 | dialog = new InputDialog("title", "msg") { 59 | @Override 60 | public void open() { 61 | okButton.notifyListeners(SWT.Selection, new Event()); 62 | } 63 | }; 64 | assertEquals("foo", dialog.open("foo")); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/SWTTestCase.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui; 8 | 9 | import org.eclipse.swt.widgets.Display; 10 | import org.eclipse.swt.widgets.Shell; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | 14 | /** 15 | * SWTTestCase - base class for SWT tests 16 | * 17 | * @author Anton Keks 18 | */ 19 | public abstract class SWTTestCase { 20 | protected static final Display display = Display.getDefault(); 21 | 22 | protected Shell shell; 23 | 24 | @Before 25 | public void setUp() { 26 | newShell(); 27 | } 28 | 29 | protected void newShell() { 30 | disposeShell(); 31 | shell = new Shell(display); 32 | } 33 | 34 | private void disposeShell() { 35 | if (shell != null) { 36 | shell.dispose(); 37 | shell = null; 38 | } 39 | } 40 | 41 | @After 42 | public void tearDown() { 43 | display.syncExec(new Runnable() { 44 | public void run() { 45 | disposeShell(); 46 | } 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/SelectFetchersDialogTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.gui; 7 | 8 | import static org.mockito.Mockito.*; 9 | 10 | import net.azib.ipscan.fetchers.FetcherRegistry; 11 | 12 | import org.junit.Test; 13 | 14 | /** 15 | * @author Anton Keks 16 | */ 17 | public class SelectFetchersDialogTest { 18 | 19 | @Test 20 | public void testSaveFetchersToRegistry() { 21 | FetcherRegistry fetcherRegistry = mock(FetcherRegistry.class); 22 | 23 | SelectFetchersDialog selectFetchersDialog = new SelectFetchersDialog(fetcherRegistry); 24 | 25 | selectFetchersDialog.registeredFetcherIdsByNames.put("IP", "fetcher.ip"); 26 | selectFetchersDialog.registeredFetcherIdsByNames.put("Hello", "fetcher.hello"); 27 | selectFetchersDialog.registeredFetcherIdsByNames.put("Blah", "fetcher.blah"); 28 | 29 | selectFetchersDialog.saveFetchersToRegistry(new String[] {"Blah", "Hello"}); 30 | 31 | verify(fetcherRegistry).updateSelectedFetchers(new String[] {"fetcher.ip", "fetcher.blah", "fetcher.hello"}); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/actions/StartStopScanningActionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.gui.actions; 8 | 9 | import static org.junit.Assert.assertNotNull; 10 | import net.azib.ipscan.core.state.ScanningState; 11 | 12 | import org.eclipse.swt.widgets.Display; 13 | import org.junit.Test; 14 | 15 | 16 | /** 17 | * StartStopScanningActionTest 18 | * 19 | * @author Anton Keks 20 | */ 21 | public class StartStopScanningActionTest { 22 | 23 | @Test 24 | public void testAllImagesAreDefined() throws Exception { 25 | StartStopScanningAction action = new StartStopScanningAction(Display.getDefault()); 26 | for (ScanningState state : ScanningState.values()) { 27 | assertNotNull(action.buttonImages[state.ordinal()]); 28 | assertNotNull(action.buttonTexts[state.ordinal()]); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/feeders/AbstractFeederGUITest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.feeders; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.feeders.Feeder; 5 | import net.azib.ipscan.feeders.RangeFeeder; 6 | import org.eclipse.swt.widgets.Shell; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertTrue; 12 | 13 | /** 14 | * AbstractFeederGUITest 15 | * 16 | * @author Anton Keks 17 | */ 18 | public class AbstractFeederGUITest { 19 | private boolean initialized; 20 | private AbstractFeederGUI feederGUI; 21 | 22 | @Before 23 | public void setUp() throws Exception { 24 | feederGUI = new AbstractFeederGUI(new Shell()) { 25 | public void initialize() { 26 | initialized = true; 27 | } 28 | public String getFeederName() { 29 | return "Mega Feeder"; 30 | } 31 | public Feeder createFeeder() { 32 | feeder = new RangeFeeder("127.0.0.1", "127.0.0.2"); 33 | return feeder; 34 | } 35 | public String[] serialize() { 36 | return new String[0]; 37 | } 38 | public void unserialize(String[] parts) { 39 | } 40 | public String[] serializePartsLabels() { 41 | return new String[0]; 42 | } 43 | }; 44 | } 45 | 46 | @Test 47 | public void initializeMustBeCalledInConstructor() throws Exception { 48 | assertTrue("otherwise command-line will be broken", initialized); 49 | } 50 | 51 | @Test 52 | public void getInfo() { 53 | assertEquals("Mega Feeder: 127.0.0.1 - 127.0.0.2", feederGUI.getInfo()); 54 | } 55 | 56 | @Test 57 | public void serializePartsAreLabels() throws Exception { 58 | // TODO: make test for each FeederGUI, extending this class 59 | for (String label : feederGUI.serializePartsLabels()) { 60 | Labels.getLabel(label); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/feeders/FeederGUIRegistryTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.feeders; 2 | 3 | import net.azib.ipscan.config.Labels; 4 | import net.azib.ipscan.feeders.Feeder; 5 | import org.eclipse.swt.widgets.Shell; 6 | import org.eclipse.swt.widgets.TableItem; 7 | import org.junit.After; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | import java.util.Collections; 12 | 13 | import static org.junit.Assert.*; 14 | import static org.mockito.Mockito.*; 15 | 16 | public class FeederGUIRegistryTest { 17 | private FeederArea parent; 18 | private FeederGUIRegistry registry; 19 | private FeederSelectionCombo feederSelectionCombo; 20 | private RangeFeederGUI feederGUI; 21 | 22 | @Before 23 | public void createRegistry() { 24 | parent = new FeederArea(new Shell()); 25 | 26 | feederSelectionCombo = mock(FeederSelectionCombo.class); 27 | 28 | feederGUI = new RangeFeederGUI(parent); 29 | feederGUI.initialize(); 30 | registry = new FeederGUIRegistry(Collections.singletonList(feederGUI), feederSelectionCombo, null); 31 | } 32 | 33 | @After 34 | public void dispose() { 35 | parent.dispose(); 36 | } 37 | 38 | @Test 39 | public void addFeederNamesToTheCombo() throws Exception { 40 | reset(feederSelectionCombo); 41 | new FeederGUIRegistry(Collections.singletonList(feederGUI), feederSelectionCombo, null); 42 | verify(feederSelectionCombo).add(Labels.getLabel(feederGUI.getFeederId())); 43 | } 44 | 45 | @Test 46 | public void lastFeederIsNeverNull() throws Exception { 47 | assertNotNull(registry.lastFeeder); 48 | assertNotNull(registry.lastFeeder.toString()); 49 | } 50 | 51 | @Test 52 | public void createFeederRemembersTheLastOne() throws Exception { 53 | Feeder lastFeeder = registry.createFeeder(); 54 | assertSame(lastFeeder, registry.lastFeeder); 55 | assertNotSame(lastFeeder, registry.createFeeder()); 56 | } 57 | 58 | @Test 59 | public void createRescanFeederGetsOriginalFeeder() throws Exception { 60 | Feeder lastFeeder = registry.createFeeder(); 61 | Feeder rescanFeeder = registry.createRescanFeeder(new TableItem[] {mock(TableItem.class)}); 62 | assertEquals(lastFeeder.getId(), rescanFeeder.getId()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/gui/fetchers/PortTextFetcherPrefsTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.gui.fetchers; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class PortTextFetcherPrefsTest { 8 | @Test 9 | public void toEditableText() { 10 | assertEquals("Hello\\r\\nand\\x05\\x19", PortTextFetcherPrefs.toEditableText("Hello\r\nand\u0005\u0019")); 11 | } 12 | 13 | @Test 14 | public void toRealText() { 15 | assertEquals("Hello\r\nand\u0005\u0019", PortTextFetcherPrefs.toRealText("Hello\\r\\nand\\x05\\x19")); 16 | } 17 | } -------------------------------------------------------------------------------- /test/net/azib/ipscan/util/GoogleAnalyticsTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.util; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.IOException; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class GoogleAnalyticsTest { 10 | @Test 11 | public void extractFirstStackFrame() { 12 | assertEquals("java.lang.RuntimeException: Kaboom\n" + 13 | "net.azib.ipscan.util.GoogleAnalyticsTest.extractFirstStackFrame:12", 14 | GoogleAnalytics.extractFirstStackFrame(new RuntimeException("Kaboom"))); 15 | } 16 | 17 | @Test 18 | public void extractFirstStackFrameWithCause() { 19 | assertEquals("java.lang.IllegalArgumentException: Kaboom\n" + 20 | "net.azib.ipscan.util.GoogleAnalyticsTest.extractFirstStackFrameWithCause:19;\n" + 21 | "java.io.IOException: The real stuff\n" + 22 | "net.azib.ipscan.util.GoogleAnalyticsTest.extractFirstStackFrameWithCause:19", 23 | GoogleAnalytics.extractFirstStackFrame(new IllegalArgumentException("Kaboom", new IOException("The real stuff")))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/util/MDNSResolverTest.java: -------------------------------------------------------------------------------- 1 | package net.azib.ipscan.util; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | import java.net.InetAddress; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class MDNSResolverTest { 13 | MDNSResolver resolver; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | resolver = new MDNSResolver(3000); 18 | } 19 | 20 | @Test 21 | public void encodeNameForDNS() throws Exception { 22 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 23 | DataOutputStream out = new DataOutputStream(baos); 24 | resolver.writeName(out, "a.bb.ccc.dddd"); 25 | assertEquals("\u0001a\u0002bb\u0003ccc\u0004dddd\u0000", new String(baos.toByteArray())); 26 | } 27 | 28 | @Test 29 | public void decodeNameFromDNS() throws Exception { 30 | byte[] data = "\u0000\u0000\u0001a\u0002bb\u0003ccc\u0004dddd\u0000".getBytes(); 31 | assertEquals("a.bb.ccc.dddd", resolver.decodeName(data, 2, data.length - 2)); 32 | } 33 | 34 | @Test 35 | public void reverseLookupName() throws Exception { 36 | assertEquals("2.0.168.192.in-addr.arpa", resolver.reverseName(InetAddress.getByName("192.168.0.2").getAddress())); 37 | } 38 | } -------------------------------------------------------------------------------- /test/net/azib/ipscan/util/NetBIOSResolverTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | 7 | package net.azib.ipscan.util; 8 | 9 | import org.junit.Test; 10 | 11 | import static org.junit.Assert.assertArrayEquals; 12 | 13 | public class NetBIOSResolverTest { 14 | @Test 15 | public void extractNamesNoUserNoGroup() throws Exception { 16 | byte[] response = ("01234567890123456789012345678901234567890123456789012345\u0001" + 17 | "ComputerName XYY" + 18 | "\u00DE\u00AD\u00BE\u00EF\u0000\u0000 XYY" 19 | ).getBytes("ISO-8859-1"); 20 | assertArrayEquals(new String[]{"ComputerName", null, null, "DE-AD-BE-EF-00-00"}, NetBIOSResolver.extractNames(response, 1)); 21 | } 22 | 23 | @Test 24 | public void extractNamesNoUserWithGroup() throws Exception { 25 | byte[] response = ("01234567890123456789012345678901234567890123456789012345\u0002" + 26 | "ComputerName XYY" + 27 | "GroupName \u0000\u0080\u0000" + 28 | "\u0001\u0002\u0003\u0004\u0005\u0006 XYY" 29 | ).getBytes("ISO-8859-1"); 30 | assertArrayEquals(new String[] {"ComputerName", null, "GroupName", "01-02-03-04-05-06"}, NetBIOSResolver.extractNames(response, 2)); 31 | } 32 | 33 | @Test 34 | public void extractNamesWithUserAndGroup() throws Exception { 35 | byte[] response = ("01234567890123456789012345678901234567890123456789012345\u0007" + 36 | "ComputerName XYY" + 37 | "SomeName X\u007F\u0000" + 38 | "SomeName X\u0085\u0000" + 39 | "GroupName \u0000\u0085\u0000" + 40 | "WrongUserName \u0003YY" + 41 | "UserName \u0003YY" + 42 | "SomeName XYY" + 43 | "\u00DE\u00AD\u00BE\u00EF\u0000\u0000 XYY" 44 | ).getBytes("ISO-8859-1"); 45 | assertArrayEquals(new String[] {"ComputerName", "UserName", "GroupName", "DE-AD-BE-EF-00-00"}, NetBIOSResolver.extractNames(response, 7)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/net/azib/ipscan/util/SequenceIteratorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is a part of Angry IP Scanner source code, 3 | * see http://www.angryip.org/ for more information. 4 | * Licensed under GPLv2. 5 | */ 6 | package net.azib.ipscan.util; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.Arrays; 11 | import java.util.Iterator; 12 | 13 | import org.junit.Test; 14 | 15 | /** 16 | * SequenceIteratorTest 17 | * 18 | * @author Anton Keks 19 | */ 20 | @SuppressWarnings("unchecked") 21 | public class SequenceIteratorTest { 22 | 23 | @Test 24 | public void singleIterator() throws Exception { 25 | Iterator i = new SequenceIterator(Arrays.asList(1).iterator()); 26 | assertTrue(i.hasNext()); 27 | assertEquals(1, (int)i.next()); 28 | assertFalse(i.hasNext()); 29 | } 30 | 31 | @Test 32 | public void twoIterators() throws Exception { 33 | Iterator i = new SequenceIterator(Arrays.asList(1, 2).iterator(), Arrays.asList(3).iterator()); 34 | assertTrue(i.hasNext()); 35 | assertEquals(1, (int)i.next()); 36 | assertTrue(i.hasNext()); 37 | assertEquals(2, (int)i.next()); 38 | assertTrue(i.hasNext()); 39 | assertEquals(3, (int)i.next()); 40 | assertFalse(i.hasNext()); 41 | } 42 | 43 | @Test 44 | public void firstEmpty() throws Exception { 45 | Iterator i = new SequenceIterator(Arrays.asList().iterator(), Arrays.asList(3).iterator()); 46 | assertTrue(i.hasNext()); 47 | assertEquals(3, (int)i.next()); 48 | assertFalse(i.hasNext()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /update-mac-vendors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This scripts downloads and optimizes IEEE MAC vendor list 3 | 4 | SED_APP='sed' 5 | if [ "$(uname)" = "Darwin" ]; then 6 | # Mac users: bundled sed doesn't have -r 7 | brew install gnu-sed 8 | SED_APP='gsed' 9 | fi 10 | 11 | curl 'https://standards-oui.ieee.org/oui/oui.txt' |\ 12 | fgrep '(base 16)' | $SED_APP -r ' 13 | s/\r//g; s/ \(base 16\)\t\t// 14 | s/,? ?(Inc)\.?$//I 15 | s/(,|, | )(Ltd|CO,\.LTD|Limited|GmbH|LLC|A\/S|AB|AS|SAS|AG|KG|PLC|SRL|OY|Oy|BV|Nederland BV|SAN VE TIC)\.?$//Ig 16 | s/(,|, | )(Co|Corp|Corporation|Company|Incorporated)\.?$//Ig 17 | s/\(.+\)// 18 | s/ (Electronics?|Technology|Technologies|Telecommunication|Communications?|Corporation|Systems|Solutions|International|Industry|Industries|Networks?|Holdings?|Device$) ?//Ig 19 | s/ (Registration Authority| MobilityCommunication)// 20 | s/SAMSUNG ELECTRO[- ]MECHANICS/Samsung/ 21 | ' | cut -c -42 | sort \ 22 | > resources/mac-vendors.txt 23 | 24 | wc -l resources/mac-vendors.txt 25 | --------------------------------------------------------------------------------