支持自定义远程主机IP地址 -s 127.0.0.1:80 或者 -s 80 这时默认 -s 0.0.0.0:80

This commit is contained in:
aixiao 2023-09-27 16:36:39 +08:00
parent b8f20c3a09
commit 32b7b5bda0
5 changed files with 33 additions and 2 deletions

Binary file not shown.

View File

@ -12,7 +12,7 @@ char *server_ssh_passwd = "123456";
const char *local_listenip = "0.0.0.0"; const char *local_listenip = "0.0.0.0";
unsigned int local_listenport = 3009; unsigned int local_listenport = 3009;
const char *remote_desthost = "0.0.0.0"; /* resolved by the server */ char *remote_desthost = "0.0.0.0"; /* resolved by the server */
unsigned int remote_destport = 3306; unsigned int remote_destport = 3306;
enum { enum {
@ -279,6 +279,7 @@ int main(int argc, char *argv[], char **env)
int listensock = -1, forwardsock = -1; int listensock = -1, forwardsock = -1;
int daemon_ = 0; int daemon_ = 0;
int opt; int opt;
char *p = NULL;
char optstring[] = ":dr:s:p:l:u:e:h?"; char optstring[] = ":dr:s:p:l:u:e:h?";
@ -291,7 +292,24 @@ int main(int argc, char *argv[], char **env)
server_ssh_ip = strdup(optarg); server_ssh_ip = strdup(optarg);
break; break;
case 's': case 's':
remote_destport = atoi(optarg); p = strchr(optarg, ':');
if (p != NULL) {
remote_destport = atoi(p + 1);
*p = '\0';
remote_desthost = optarg;
} else {
if (NULL == (p = strchr(optarg, '.')))
{
remote_destport =atoi(optarg);
remote_desthost = "0.0.0.0";
} else {
help_info();
exit(0);
}
}
break; break;
case 'p': case 'p':
server_ssh_port = atoi(optarg); server_ssh_port = atoi(optarg);
@ -315,6 +333,19 @@ int main(int argc, char *argv[], char **env)
} }
} }
int i, j;
for (i = 1; i < argc; i++) {
if (0 == strcmp(argv[i], "-e") || 0 == strcmp(argv[i], "-u") || 0 == strcmp(argv[i], "-p"))
{
for (j = strlen(argv[i+1]) - 1; j >= 0; j--) {
argv[i+1][j] = 'x';
}
}
}
printf("SSH Server: %s:%d, Local listen: %s:%d, User&Passwd: [%s]['%s']\n", server_ssh_ip, remote_destport, local_listenip, local_listenport, server_ssh_user, server_ssh_passwd); printf("SSH Server: %s:%d, Local listen: %s:%d, User&Passwd: [%s]['%s']\n", server_ssh_ip, remote_destport, local_listenip, local_listenport, server_ssh_user, server_ssh_passwd);

Binary file not shown.

Binary file not shown.

Binary file not shown.