Created
November 8, 2026 05:03
-
-
Save asdf913/e4b5a2a15fd4864bb972bf394eb49f93 to your computer and use it in GitHub Desktop.
Putty Configuration Registry Report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependencies> | |
| <!--https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform --> | |
| <dependency> | |
| <groupId>net.java.dev.jna</groupId> | |
| <artifactId>jna-platform</artifactId> | |
| <version>5.19.1</version> | |
| </dependency> | |
| <!--https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> | |
| <dependency> | |
| <groupId>org.apache.commons</groupId> | |
| <artifactId>commons-lang3</artifactId> | |
| <version>3.21.0</version> | |
| </dependency> | |
| </dependencies> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.nio.file.FileSystems; | |
| import java.util.Collections; | |
| import java.util.LinkedHashMap; | |
| import java.util.Map; | |
| import java.util.Map.Entry; | |
| import java.util.Objects; | |
| import java.util.function.BiFunction; | |
| import org.apache.commons.lang3.ArrayUtils; | |
| import org.apache.commons.lang3.StringUtils; | |
| import com.sun.jna.platform.win32.Advapi32Util; | |
| import com.sun.jna.platform.win32.WinReg; | |
| import com.sun.jna.platform.win32.WinReg.HKEY; | |
| public class PutyConfigurationRegistryReport { | |
| public static void main(final String[] args) { | |
| // | |
| if (!Objects.equals(getName(getClass(FileSystems.getDefault())), "sun.nio.fs.WindowsFileSystem")) { | |
| // | |
| System.out.println("Please run under Microsoft Windows"); | |
| // | |
| return; | |
| // | |
| } // if | |
| // | |
| final HKEY hkey = WinReg.HKEY_CURRENT_USER; | |
| // | |
| final String path = "Software\\SimonTatham\\PuTTY\\Sessions"; | |
| // | |
| if (!Advapi32Util.registryKeyExists(hkey, path)) { | |
| // | |
| System.out.println("No Putty Configuration found in the registry"); | |
| // | |
| return; | |
| // | |
| } // if | |
| // | |
| final String[] keys = Advapi32Util.registryGetKeys(hkey, path); | |
| // | |
| final Map<String, BiFunction<String, String, Object>> map = new LinkedHashMap<>( | |
| Collections.singletonMap("HostName", (a, b) -> Advapi32Util.registryGetStringValue(hkey, a, b))); | |
| // | |
| map.put("PortNumber", (a, b) -> Advapi32Util.registryGetIntValue(hkey, a, b)); | |
| // | |
| map.put("UserName", (a, b) -> Advapi32Util.registryGetStringValue(hkey, a, b)); | |
| // | |
| map.put("PublicKeyFile", (a, b) -> Advapi32Util.registryGetStringValue(hkey, a, b)); | |
| // | |
| final int maxKeyLength = map.keySet().stream().mapToInt(StringUtils::length).max().orElse(0); | |
| // | |
| String key, sessionPath = null; | |
| // | |
| for (int i = 0; keys != null && i < keys.length && map != null && map.entrySet() != null | |
| && map.entrySet().iterator() != null; i++) { | |
| // | |
| System.out.println(key = ArrayUtils.get(keys, i)); | |
| // | |
| sessionPath = StringUtils.joinWith("\\", path, key); | |
| // | |
| for (final Entry<String, BiFunction<String, String, Object>> entry : map.entrySet()) { | |
| // | |
| if (entry == null || entry.getValue() == null) { | |
| // | |
| continue; | |
| // | |
| } // if | |
| // | |
| if (Advapi32Util.registryValueExists(hkey, sessionPath, key = entry.getKey())) { | |
| // | |
| System.out.printf("%1$s=%2$s%3$s", StringUtils.rightPad(key, maxKeyLength), | |
| entry.getValue().apply(sessionPath, key), System.lineSeparator()); | |
| // | |
| } // if | |
| // | |
| } // for | |
| // | |
| } // for | |
| // | |
| } | |
| private static String getName(final Class<?> instance) { | |
| return instance != null ? instance.getName() : null; | |
| } | |
| private static Class<?> getClass(final Object instance) { | |
| return instance != null ? instance.getClass() : null; | |
| } | |
| } |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Sample Output under Microsoft Windows