{"id":813,"date":"2025-11-19T11:33:59","date_gmt":"2025-11-19T03:33:59","guid":{"rendered":"https:\/\/help.ipnut.com\/?post_type=docs&#038;p=813"},"modified":"2025-11-23T18:31:54","modified_gmt":"2025-11-23T10:31:54","password":"","slug":"java-integration-demo-ipnut-proxy-configuration-via-java","status":"publish","type":"docs","link":"https:\/\/www.ipnut.com\/help\/development-documentation\/java-integration-demo-ipnut-proxy-configuration-via-java\/","title":{"rendered":"Java Integration Demo IPNut Proxy Configuration via Java"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"813\" class=\"elementor elementor-813\" data-elementor-post-type=\"docs\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e9e2505 e-flex e-con-boxed e-con e-parent\" data-id=\"e9e2505\" data-element_type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-a2b9df5 elementor-widget elementor-widget-text-editor\" data-id=\"a2b9df5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p style=\"margin-top: 16px; margin-bottom: 16px; color: #0f1115; font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-size: 16px; font-style: normal; font-weight: 400;\">After purchasing static IP services from IPNut platform, use the following Java code samples for integration.<\/p><hr style=\"background: none 0% 0% \/ auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.1); border-width: initial; border-style: none; margin-top: 32px; margin-bottom: 32px; font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-size: 16px; font-style: normal; font-weight: 400;\" \/><p>\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2e01b4c elementor-widget elementor-widget-heading\" data-id=\"2e01b4c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">1. SOCKS5 Proxy Implementation\nSocks5ProxyDemo.java<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e43502d elementor-widget elementor-widget-code-highlight\" data-id=\"e43502d\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java \">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>import java.io.*;\r\nimport java.net.*;\r\nimport java.net.http.HttpClient;\r\nimport java.net.http.HttpRequest;\r\nimport java.net.http.HttpResponse;\r\nimport java.time.Duration;\r\n\r\npublic class Socks5ProxyDemo {\r\n\r\n    \/\/ Proxy configuration (replace with your credentials)\r\n    private static final String PROXY_HOST = \"proxy.ipnut.com\";\r\n    private static final int PROXY_PORT = 28001;\r\n    private static final String PROXY_USERNAME = \"ipnut\";\r\n    private static final String PROXY_PASSWORD = \"123456789\";\r\n\r\n    public static void main(String[] args) {\r\n        System.out.println(\"=== IPNut SOCKS5 Proxy Demo ===\\n\");\r\n\r\n        socks5WithHttpClient();\r\n        socks5WithSocket();\r\n        socks5WithCustomRequest();\r\n    }\r\n\r\n    \/**\r\n     * SOCKS5 Proxy using Java 11+ HttpClient\r\n     *\/\r\n    public static void socks5WithHttpClient() {\r\n        System.out.println(\"1. SOCKS5 Proxy with HttpClient:\");\r\n\r\n        try {\r\n            \/\/ Create SOCKS5 proxy selector\r\n            ProxySelector proxySelector = new ProxySelector() {\r\n                @Override\r\n                public java.util.List<Proxy> select(URI uri) {\r\n                    return java.util.List.of(\r\n                        new Proxy(Proxy.Type.SOCKS, \r\n                            new InetSocketAddress(PROXY_HOST, PROXY_PORT))\r\n                    );\r\n                }\r\n\r\n                @Override\r\n                public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {\r\n                    System.err.println(\"Connection failed: \" + uri + \" - \" + ioe.getMessage());\r\n                }\r\n            };\r\n\r\n            \/\/ Create HttpClient with SOCKS5 proxy\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .proxy(proxySelector)\r\n                .connectTimeout(Duration.ofSeconds(30))\r\n                .version(HttpClient.Version.HTTP_1_1)\r\n                .build();\r\n\r\n            \/\/ Create HTTP request\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/ip\"))\r\n                .timeout(Duration.ofSeconds(30))\r\n                .header(\"User-Agent\", \"IPNut-Java-Client\/1.0\")\r\n                .GET()\r\n                .build();\r\n\r\n            \/\/ Execute request\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"Status Code: \" + response.statusCode());\r\n            System.out.println(\"Response: \" + response.body());\r\n            System.out.println(\"\u2705 SOCKS5 Proxy test completed successfully\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Request failed: \" + e.getMessage());\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * SOCKS5 Proxy using raw Socket connection\r\n     *\/\r\n    public static void socks5WithSocket() {\r\n        System.out.println(\"\\n2. SOCKS5 Proxy with Socket:\");\r\n\r\n        Socket socket = null;\r\n        try {\r\n            \/\/ Create proxy configuration\r\n            Proxy proxy = new Proxy(Proxy.Type.SOCKS,\r\n                new InetSocketAddress(PROXY_HOST, PROXY_PORT));\r\n\r\n            \/\/ Create socket connection through proxy\r\n            socket = new Socket(proxy);\r\n            socket.connect(new InetSocketAddress(\"httpbin.org\", 80), 30000);\r\n\r\n            \/\/ Send HTTP request\r\n            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);\r\n            BufferedReader in = new BufferedReader(\r\n                new InputStreamReader(socket.getInputStream()));\r\n\r\n            \/\/ Build HTTP request\r\n            String request = \"GET \/ip HTTP\/1.1\\r\\n\" +\r\n                           \"Host: httpbin.org\\r\\n\" +\r\n                           \"User-Agent: IPNut-SOCKS5-Socket-Client\\r\\n\" +\r\n                           \"Accept: application\/json\\r\\n\" +\r\n                           \"Connection: close\\r\\n\\r\\n\";\r\n\r\n            out.print(request);\r\n            out.flush();\r\n\r\n            \/\/ Read response\r\n            String line;\r\n            StringBuilder response = new StringBuilder();\r\n            while ((line = in.readLine()) != null) {\r\n                response.append(line).append(\"\\n\");\r\n            }\r\n\r\n            System.out.println(\"Response received:\");\r\n            System.out.println(response.toString());\r\n            System.out.println(\"\u2705 SOCKS5 Socket test completed successfully\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Socket request failed: \" + e.getMessage());\r\n        } finally {\r\n            if (socket != null) {\r\n                try {\r\n                    socket.close();\r\n                } catch (IOException e) {\r\n                    System.err.println(\"Socket close error: \" + e.getMessage());\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * SOCKS5 Proxy with custom configuration\r\n     *\/\r\n    public static void socks5WithCustomRequest() {\r\n        System.out.println(\"\\n3. SOCKS5 Proxy with Custom Request:\");\r\n\r\n        try {\r\n            \/\/ Set SOCKS5 proxy system properties\r\n            System.setProperty(\"socksProxyHost\", PROXY_HOST);\r\n            System.setProperty(\"socksProxyPort\", String.valueOf(PROXY_PORT));\r\n\r\n            \/\/ Create HttpClient\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(30))\r\n                .build();\r\n\r\n            \/\/ Create custom request with headers\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/headers\"))\r\n                .header(\"User-Agent\", \"IPNut-Custom-Client\/1.0\")\r\n                .header(\"Accept\", \"application\/json\")\r\n                .header(\"X-Proxy-Type\", \"SOCKS5\")\r\n                .header(\"X-Client-ID\", \"IPNut-Java-Demo\")\r\n                .timeout(Duration.ofSeconds(30))\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"Status Code: \" + response.statusCode());\r\n            System.out.println(\"Custom Headers Response: \" + response.body());\r\n            System.out.println(\"\u2705 Custom SOCKS5 request test completed\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Custom request failed: \" + e.getMessage());\r\n        } finally {\r\n            \/\/ Clean up system properties\r\n            System.clearProperty(\"socksProxyHost\");\r\n            System.clearProperty(\"socksProxyPort\");\r\n        }\r\n    }\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9538d52 elementor-widget elementor-widget-heading\" data-id=\"9538d52\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">2. HTTP Proxy Implementation\nHttpProxyDemo.java<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-29c2ca2 elementor-widget elementor-widget-code-highlight\" data-id=\"29c2ca2\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java \">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>import java.io.*;\r\nimport java.net.*;\r\nimport java.net.http.HttpClient;\r\nimport java.net.http.HttpRequest;\r\nimport java.net.http.HttpResponse;\r\nimport java.time.Duration;\r\nimport java.util.Base64;\r\n\r\npublic class HttpProxyDemo {\r\n\r\n    \/\/ Proxy configuration\r\n    private static final String PROXY_HOST = \"proxy.ipnut.com\";\r\n    private static final int PROXY_PORT = 28001;\r\n    private static final String PROXY_USERNAME = \"ipnut\";\r\n    private static final String PROXY_PASSWORD = \"123456789\";\r\n\r\n    public static void main(String[] args) {\r\n        System.out.println(\"=== IPNut HTTP Proxy Demo ===\\n\");\r\n\r\n        httpProxyWithHttpClient();\r\n        httpProxyWithAuthenticator();\r\n        httpProxyWithSocket();\r\n        httpProxyMultipleRequests();\r\n    }\r\n\r\n    \/**\r\n     * HTTP Proxy using HttpClient with proxy selector\r\n     *\/\r\n    public static void httpProxyWithHttpClient() {\r\n        System.out.println(\"1. HTTP Proxy with HttpClient:\");\r\n\r\n        try {\r\n            \/\/ Create HTTP proxy selector\r\n            ProxySelector proxySelector = new ProxySelector() {\r\n                @Override\r\n                public java.util.List<Proxy> select(URI uri) {\r\n                    return java.util.List.of(\r\n                        new Proxy(Proxy.Type.HTTP, \r\n                            new InetSocketAddress(PROXY_HOST, PROXY_PORT))\r\n                    );\r\n                }\r\n\r\n                @Override\r\n                public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {\r\n                    System.err.println(\"Proxy connection failed: \" + ioe.getMessage());\r\n                }\r\n            };\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .proxy(proxySelector)\r\n                .connectTimeout(Duration.ofSeconds(30))\r\n                .build();\r\n\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/ip\"))\r\n                .timeout(Duration.ofSeconds(30))\r\n                .header(\"User-Agent\", \"IPNut-HTTP-Client\/1.0\")\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"Status Code: \" + response.statusCode());\r\n            System.out.println(\"Response: \" + response.body());\r\n            System.out.println(\"\u2705 HTTP Proxy test completed successfully\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c HTTP Proxy request failed: \" + e.getMessage());\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * HTTP Proxy with authentication using Authenticator\r\n     *\/\r\n    public static void httpProxyWithAuthenticator() {\r\n        System.out.println(\"\\n2. HTTP Proxy with Authentication:\");\r\n\r\n        try {\r\n            \/\/ Set up proxy authentication\r\n            Authenticator.setDefault(new Authenticator() {\r\n                @Override\r\n                protected PasswordAuthentication getPasswordAuthentication() {\r\n                    if (getRequestorType() == Authenticator.RequestorType.PROXY) {\r\n                        return new PasswordAuthentication(PROXY_USERNAME,\r\n                            PROXY_PASSWORD.toCharArray());\r\n                    }\r\n                    return null;\r\n                }\r\n            });\r\n\r\n            \/\/ Configure system proxy settings\r\n            System.setProperty(\"http.proxyHost\", PROXY_HOST);\r\n            System.setProperty(\"http.proxyPort\", String.valueOf(PROXY_PORT));\r\n            System.setProperty(\"https.proxyHost\", PROXY_HOST);\r\n            System.setProperty(\"https.proxyPort\", String.valueOf(PROXY_PORT));\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(30))\r\n                .build();\r\n\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/ip\"))\r\n                .timeout(Duration.ofSeconds(30))\r\n                .header(\"User-Agent\", \"IPNut-Auth-Client\/1.0\")\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"Status Code: \" + response.statusCode());\r\n            System.out.println(\"Response: \" + response.body());\r\n            System.out.println(\"\u2705 Authenticated HTTP Proxy test completed\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Authenticated request failed: \" + e.getMessage());\r\n        } finally {\r\n            \/\/ Clean up\r\n            Authenticator.setDefault(null);\r\n            System.clearProperty(\"http.proxyHost\");\r\n            System.clearProperty(\"http.proxyPort\");\r\n            System.clearProperty(\"https.proxyHost\");\r\n            System.clearProperty(\"https.proxyPort\");\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * HTTP Proxy using raw Socket with manual authentication\r\n     *\/\r\n    public static void httpProxyWithSocket() {\r\n        System.out.println(\"\\n3. HTTP Proxy with Socket (Manual Auth):\");\r\n\r\n        Socket socket = null;\r\n        try {\r\n            \/\/ Connect to proxy server\r\n            socket = new Socket(PROXY_HOST, PROXY_PORT);\r\n\r\n            \/\/ Build proxy authentication\r\n            String credentials = PROXY_USERNAME + \":\" + PROXY_PASSWORD;\r\n            String encodedCredentials = Base64.getEncoder()\r\n                .encodeToString(credentials.getBytes());\r\n\r\n            \/\/ Send CONNECT request to proxy\r\n            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);\r\n            BufferedReader in = new BufferedReader(\r\n                new InputStreamReader(socket.getInputStream()));\r\n\r\n            String connectRequest = \"CONNECT httpbin.org:443 HTTP\/1.1\\r\\n\" +\r\n                                  \"Host: httpbin.org:443\\r\\n\" +\r\n                                  \"Proxy-Authorization: Basic \" + encodedCredentials + \"\\r\\n\" +\r\n                                  \"Connection: keep-alive\\r\\n\\r\\n\";\r\n\r\n            out.print(connectRequest);\r\n            out.flush();\r\n\r\n            \/\/ Read proxy response\r\n            String line;\r\n            while ((line = in.readLine()) != null) {\r\n                if (line.isEmpty()) break;\r\n                if (line.contains(\"200\")) {\r\n                    System.out.println(\"\u2705 Proxy connection established\");\r\n                }\r\n            }\r\n\r\n            \/\/ For HTTPS, you would need to handle SSL handshake\r\n            \/\/ This example shows the CONNECT method for tunneling\r\n\r\n            System.out.println(\"\u2705 HTTP Proxy Socket test completed\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Socket proxy request failed: \" + e.getMessage());\r\n        } finally {\r\n            if (socket != null) {\r\n                try {\r\n                    socket.close();\r\n                } catch (IOException e) {\r\n                    System.err.println(\"Socket close error: \" + e.getMessage());\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * Multiple requests through HTTP Proxy\r\n     *\/\r\n    public static void httpProxyMultipleRequests() {\r\n        System.out.println(\"\\n4. Multiple Requests through HTTP Proxy:\");\r\n\r\n        try {\r\n            \/\/ Configure proxy\r\n            System.setProperty(\"http.proxyHost\", PROXY_HOST);\r\n            System.setProperty(\"http.proxyPort\", String.valueOf(PROXY_PORT));\r\n\r\n            \/\/ Set up authentication\r\n            Authenticator.setDefault(new Authenticator() {\r\n                @Override\r\n                protected PasswordAuthentication getPasswordAuthentication() {\r\n                    return new PasswordAuthentication(PROXY_USERNAME,\r\n                        PROXY_PASSWORD.toCharArray());\r\n                }\r\n            });\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(30))\r\n                .build();\r\n\r\n            String[] testEndpoints = {\r\n                \"https:\/\/httpbin.org\/ip\",\r\n                \"https:\/\/httpbin.org\/user-agent\", \r\n                \"https:\/\/httpbin.org\/headers\",\r\n                \"https:\/\/httpbin.org\/get?test=ipnut_proxy\"\r\n            };\r\n\r\n            for (int i = 0; i < testEndpoints.length; i++) {\r\n                System.out.println(\"\\nRequest \" + (i + 1) + \": \" + testEndpoints[i]);\r\n\r\n                HttpRequest request = HttpRequest.newBuilder()\r\n                    .uri(URI.create(testEndpoints[i]))\r\n                    .header(\"User-Agent\", \"IPNut-Multi-Request-Client\/1.0\")\r\n                    .header(\"X-Request-ID\", \"test-\" + (i + 1))\r\n                    .timeout(Duration.ofSeconds(30))\r\n                    .GET()\r\n                    .build();\r\n\r\n                HttpResponse<String> response = client.send(request,\r\n                    HttpResponse.BodyHandlers.ofString());\r\n\r\n                System.out.println(\"Status Code: \" + response.statusCode());\r\n                System.out.println(\"Response Preview: \" + \r\n                    response.body().substring(0, Math.min(150, response.body().length())) + \"...\");\r\n\r\n                \/\/ Rate limiting\r\n                Thread.sleep(1000);\r\n            }\r\n\r\n            System.out.println(\"\\n\u2705 All multiple requests completed successfully\");\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c Multiple requests failed: \" + e.getMessage());\r\n        } finally {\r\n            \/\/ Clean up\r\n            Authenticator.setDefault(null);\r\n            System.clearProperty(\"http.proxyHost\");\r\n            System.clearProperty(\"http.proxyPort\");\r\n        }\r\n    }\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-629da98 elementor-widget elementor-widget-heading\" data-id=\"629da98\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">3. Connectivity Testing Utility\nProxyTestTool.java<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dfb40d6 elementor-widget elementor-widget-code-highlight\" data-id=\"dfb40d6\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java \">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>import java.net.*;\r\nimport java.net.http.HttpClient;\r\nimport java.net.http.HttpRequest;\r\nimport java.net.http.HttpResponse;\r\nimport java.time.Duration;\r\n\r\npublic class ProxyTestTool {\r\n\r\n    private static final String PROXY_HOST = \"proxy.ipnut.com\";\r\n    private static final int PROXY_PORT = 28001;\r\n    private static final String PROXY_USERNAME = \"ipnut\";\r\n    private static final String PROXY_PASSWORD = \"123456789\";\r\n\r\n    public static void main(String[] args) {\r\n        System.out.println(\"=== IPNut Proxy Connectivity Test ===\\n\");\r\n\r\n        testSocks5Proxy();\r\n        testHttpProxy();\r\n        comprehensiveTest();\r\n    }\r\n\r\n    \/**\r\n     * Test SOCKS5 Proxy connectivity\r\n     *\/\r\n    public static void testSocks5Proxy() {\r\n        System.out.println(\"Testing SOCKS5 Proxy Connectivity:\");\r\n\r\n        try {\r\n            \/\/ Configure SOCKS5 proxy\r\n            System.setProperty(\"socksProxyHost\", PROXY_HOST);\r\n            System.setProperty(\"socksProxyPort\", String.valueOf(PROXY_PORT));\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(15))\r\n                .build();\r\n\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/ip\"))\r\n                .timeout(Duration.ofSeconds(15))\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"\u2705 SOCKS5 Proxy Connection Successful\");\r\n            System.out.println(\"   Status Code: \" + response.statusCode());\r\n            System.out.println(\"   Assigned IP: \" + response.body());\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c SOCKS5 Proxy Connection Failed: \" + e.getMessage());\r\n        } finally {\r\n            System.clearProperty(\"socksProxyHost\");\r\n            System.clearProperty(\"socksProxyPort\");\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * Test HTTP Proxy connectivity\r\n     *\/\r\n    public static void testHttpProxy() {\r\n        System.out.println(\"\\nTesting HTTP Proxy Connectivity:\");\r\n\r\n        try {\r\n            \/\/ Configure HTTP proxy\r\n            System.setProperty(\"http.proxyHost\", PROXY_HOST);\r\n            System.setProperty(\"http.proxyPort\", String.valueOf(PROXY_PORT));\r\n\r\n            \/\/ Set up authentication\r\n            Authenticator.setDefault(new Authenticator() {\r\n                @Override\r\n                protected PasswordAuthentication getPasswordAuthentication() {\r\n                    return new PasswordAuthentication(PROXY_USERNAME,\r\n                        PROXY_PASSWORD.toCharArray());\r\n                }\r\n            });\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(15))\r\n                .build();\r\n\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(\"https:\/\/httpbin.org\/ip\"))\r\n                .timeout(Duration.ofSeconds(15))\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            System.out.println(\"\u2705 HTTP Proxy Connection Successful\");\r\n            System.out.println(\"   Status Code: \" + response.statusCode());\r\n            System.out.println(\"   Assigned IP: \" + response.body());\r\n\r\n        } catch (Exception e) {\r\n            System.err.println(\"\u274c HTTP Proxy Connection Failed: \" + e.getMessage());\r\n        } finally {\r\n            Authenticator.setDefault(null);\r\n            System.clearProperty(\"http.proxyHost\");\r\n            System.clearProperty(\"http.proxyPort\");\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * Comprehensive proxy testing\r\n     *\/\r\n    public static void comprehensiveTest() {\r\n        System.out.println(\"\\n=== Comprehensive Proxy Test ===\");\r\n\r\n        String[] testUrls = {\r\n            \"https:\/\/httpbin.org\/ip\",\r\n            \"https:\/\/httpbin.org\/user-agent\",\r\n            \"https:\/\/httpbin.org\/headers\"\r\n        };\r\n\r\n        \/\/ Test both proxy types\r\n        String[] proxyTypes = {\"SOCKS5\", \"HTTP\"};\r\n\r\n        for (String proxyType : proxyTypes) {\r\n            System.out.println(\"\\nTesting \" + proxyType + \" Proxy:\");\r\n\r\n            for (String testUrl : testUrls) {\r\n                try {\r\n                    boolean success = testProxyConnection(proxyType, testUrl);\r\n                    if (success) {\r\n                        System.out.println(\"  \u2705 \" + testUrl + \" - Success\");\r\n                    } else {\r\n                        System.out.println(\"  \u274c \" + testUrl + \" - Failed\");\r\n                    }\r\n                } catch (Exception e) {\r\n                    System.out.println(\"  \u274c \" + testUrl + \" - Error: \" + e.getMessage());\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    private static boolean testProxyConnection(String proxyType, String testUrl) {\r\n        try {\r\n            if (\"SOCKS5\".equals(proxyType)) {\r\n                System.setProperty(\"socksProxyHost\", PROXY_HOST);\r\n                System.setProperty(\"socksProxyPort\", String.valueOf(PROXY_PORT));\r\n            } else {\r\n                System.setProperty(\"http.proxyHost\", PROXY_HOST);\r\n                System.setProperty(\"http.proxyPort\", String.valueOf(PROXY_PORT));\r\n                Authenticator.setDefault(new Authenticator() {\r\n                    @Override\r\n                    protected PasswordAuthentication getPasswordAuthentication() {\r\n                        return new PasswordAuthentication(PROXY_USERNAME,\r\n                            PROXY_PASSWORD.toCharArray());\r\n                    }\r\n                });\r\n            }\r\n\r\n            HttpClient client = HttpClient.newBuilder()\r\n                .connectTimeout(Duration.ofSeconds(10))\r\n                .build();\r\n\r\n            HttpRequest request = HttpRequest.newBuilder()\r\n                .uri(URI.create(testUrl))\r\n                .timeout(Duration.ofSeconds(10))\r\n                .GET()\r\n                .build();\r\n\r\n            HttpResponse<String> response = client.send(request,\r\n                HttpResponse.BodyHandlers.ofString());\r\n\r\n            return response.statusCode() == 200;\r\n\r\n        } catch (Exception e) {\r\n            return false;\r\n        } finally {\r\n            \/\/ Clean up\r\n            if (\"SOCKS5\".equals(proxyType)) {\r\n                System.clearProperty(\"socksProxyHost\");\r\n                System.clearProperty(\"socksProxyPort\");\r\n            } else {\r\n                Authenticator.setDefault(null);\r\n                System.clearProperty(\"http.proxyHost\");\r\n                System.clearProperty(\"http.proxyPort\");\r\n            }\r\n        }\r\n    }\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6cd7641 elementor-widget elementor-widget-heading\" data-id=\"6cd7641\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">4. Compilation and Execution<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b145238 elementor-widget elementor-widget-code-highlight\" data-id=\"b145238\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java \">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp># Compilation Commands:\r\n# Compile all Java files\r\njavac *.java\r\n\r\n# Or compile individually\r\njavac Socks5ProxyDemo.java\r\njavac HttpProxyDemo.java  \r\njavac ProxyTestTool.java\r\n\r\n# Execution Commands:\r\n# Run SOCKS5 proxy demo\r\njava Socks5ProxyDemo\r\n\r\n# Run HTTP proxy demo\r\njava HttpProxyDemo\r\n\r\n# Run connectivity tests\r\njava ProxyTestTool<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-23e1b95 elementor-widget elementor-widget-heading\" data-id=\"23e1b95\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h6 class=\"elementor-heading-title elementor-size-default\">5. Project Structure &amp; Dependencies<\/h6>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6dcb603 elementor-widget elementor-widget-code-highlight\" data-id=\"6dcb603\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java \">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp># Maven Dependencies (pom.xml):\n<properties>\n    <maven.compiler.source>11<\/maven.compiler.source>\n    <maven.compiler.target>11<\/maven.compiler.target>\n<\/properties>\n\n<dependencies>\n    <!-- Required for Java 11+ HTTP Client -->\n<\/dependencies>\n\n# Gradle Dependencies (build.gradle):\nplugins {\n    id 'java'\n}\n\nsourceCompatibility = 11\ntargetCompatibility = 11\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-25cc52c elementor-widget elementor-widget-text-editor\" data-id=\"25cc52c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<hr \/><p>Key Integration Notes:<\/p><ul><li><p class=\"ds-markdown-paragraph\">Java Version: Requires Java 11 or higher for HTTP Client<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Credential Management: Replace example credentials with actual IPNut proxy details<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Error Handling: Comprehensive exception handling for production use<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Performance: Connection timeouts and proper resource management<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Security: Clean up system properties after use<\/p><\/li><\/ul><p>Best Practices:<\/p><ol start=\"1\"><li><p class=\"ds-markdown-paragraph\">Resource Management: Always close sockets and streams in finally blocks<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Timeout Configuration: Set appropriate timeouts for different operations<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Error Recovery: Implement retry mechanisms for transient failures<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Monitoring: Add logging for connection status and performance metrics<\/p><\/li><\/ol><hr \/><p class=\"ds-markdown-paragraph\">Technical Support<br \/>For integration assistance or location-specific requirements:<\/p><ul><li><p class=\"ds-markdown-paragraph\">Email:\u00a0Support@ipnut.com<\/p><\/li><li><p class=\"ds-markdown-paragraph\">Live Chat: 24\/7 real-time support via official website<\/p><\/li><\/ul><p class=\"ds-markdown-paragraph\">*All code examples support both HTTP and SOCKS5 protocols with enterprise-grade authentication and security features.*<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>After purchasing sta [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"doc_category":[45],"doc_tag":[],"class_list":["post-813","docs","type-docs","status-publish","hentry","doc_category-development-documentation"],"year_month":"2026-05","word_count":1974,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"admin","author_nicename":"admin","author_url":"https:\/\/help.ipnut.com\/author\/admin\/"},"doc_category_info":[{"term_name":"Development Documentation","term_url":"https:\/\/help.ipnut.com\/docs\/development-documentation\/"}],"doc_tag_info":[],"lang":"en","translations":{"en":813,"cn":667},"knowledge_base_info":[],"knowledge_base_slug":[],"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/comments?post=813"}],"version-history":[{"count":7,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/813\/revisions"}],"predecessor-version":[{"id":1143,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/docs\/813\/revisions\/1143"}],"wp:attachment":[{"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/media?parent=813"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/doc_category?post=813"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.ipnut.com\/wp-json\/wp\/v2\/doc_tag?post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}