-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
62 changes: 62 additions & 0 deletions
62
natx-client/src/main/java/com/xxg/natx/client/NatxClientStarter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.xxg.natx.client; | ||
|
||
import org.apache.commons.cli.*; | ||
|
||
/** | ||
* Created by wucao on 2019/2/27. | ||
*/ | ||
public class NatxClientStarter { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
// args | ||
Options options = new Options(); | ||
options.addOption("h", false, "Help"); | ||
options.addOption("server_addr", true, "Natx server address"); | ||
options.addOption("server_port", true, "Natx server port"); | ||
options.addOption("password", true, "Natx server password"); | ||
options.addOption("proxy_addr", true, "Proxy server address"); | ||
options.addOption("proxy_port", true, "Proxy server port"); | ||
options.addOption("remote_port", true, "Proxy server remote port"); | ||
|
||
CommandLineParser parser = new DefaultParser(); | ||
CommandLine cmd = parser.parse(options, args); | ||
|
||
if (cmd.hasOption("h")) { | ||
// print help | ||
HelpFormatter formatter = new HelpFormatter(); | ||
formatter.printHelp("options", options); | ||
} else { | ||
|
||
String serverAddress = cmd.getOptionValue("server_addr"); | ||
if (serverAddress == null) { | ||
System.out.println("server_addr cannot be null"); | ||
return; | ||
} | ||
String serverPort = cmd.getOptionValue("server_port"); | ||
if (serverPort == null) { | ||
System.out.println("server_port cannot be null"); | ||
return; | ||
} | ||
String password = cmd.getOptionValue("password"); | ||
String proxyAddress = cmd.getOptionValue("proxy_addr"); | ||
if (proxyAddress == null) { | ||
System.out.println("proxy_addr cannot be null"); | ||
return; | ||
} | ||
String proxyPort = cmd.getOptionValue("proxy_port"); | ||
if (proxyPort == null) { | ||
System.out.println("proxy_port cannot be null"); | ||
return; | ||
} | ||
String remotePort = cmd.getOptionValue("remote_port"); | ||
if (remotePort == null) { | ||
System.out.println("remote_port cannot be null"); | ||
return; | ||
} | ||
|
||
NatxClient client = new NatxClient(); | ||
client.connect(serverAddress, Integer.parseInt(serverPort), password, Integer.parseInt(remotePort), proxyAddress, Integer.parseInt(proxyPort)); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
natx-server/src/main/java/com/xxg/natx/server/NatxServerStarter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.xxg.natx.server; | ||
|
||
import org.apache.commons.cli.*; | ||
|
||
/** | ||
* Created by wucao on 2019/10/23. | ||
*/ | ||
public class NatxServerStarter { | ||
|
||
public static void main(String[] args) throws ParseException, InterruptedException { | ||
|
||
// args | ||
Options options = new Options(); | ||
options.addOption("h", false, "Help"); | ||
options.addOption("port", true, "Natx server port"); | ||
options.addOption("password", true, "Natx server password"); | ||
|
||
CommandLineParser parser = new DefaultParser(); | ||
CommandLine cmd = parser.parse(options, args); | ||
|
||
if (cmd.hasOption("h")) { | ||
// print help | ||
HelpFormatter formatter = new HelpFormatter(); | ||
formatter.printHelp("options", options); | ||
} else { | ||
|
||
int port = Integer.parseInt(cmd.getOptionValue("port", "7731")); | ||
String password = cmd.getOptionValue("password"); | ||
NatxServer server = new NatxServer(); | ||
server.start(port, password); | ||
|
||
System.out.println("Natx server started on port " + port); | ||
} | ||
} | ||
} |