端口映射(线上内网端口本地端口)
程序员文章站
2022-04-09 20:21:10
pom.xml com.jcraft jsch 0 ......
1 /** 2 * 端口转发 3 */ 4 public static void transpondSolrPort() { 5 try { 6 JSch jsch = new JSch(); 7 Session session = jsch.getSession("name", "host", 22); 8 session.setPassword("password"); 9 session.setConfig("StrictHostKeyChecking", "no"); 10 session.connect(); 11 session.setPortForwardingL("localhost", 8899, "192.168.1.7", 8002);//端口映射 转发 (线上内网192.168.1.7:8002转发为localhost:8899) 12 } catch (Exception ex) { 13 ex.printStackTrace(); 14 } 15 }
pom.xml
<!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>