add -p to pick proxy with arg
parent
1015efaf16
commit
490b818630
|
@ -1,6 +1,9 @@
|
|||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#define PROXYCHAINS_SOCKS5_PORT_ENV_VAR "PROXYCHAINS_SOCKS5_PORT"
|
||||
#define PROXYCHAINS_SOCKS5_HOST_ENV_VAR "PROXYCHAINS_SOCKS5_HOST"
|
||||
|
||||
#define PROXYCHAINS_CONF_FILE_ENV_VAR "PROXYCHAINS_CONF_FILE"
|
||||
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
||||
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
||||
|
|
|
@ -83,7 +83,8 @@ pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
|||
|
||||
static int init_l = 0;
|
||||
|
||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
||||
static int socks5_from_env(proxy_data *pd, unsigned int *proxy_count, chain_type *ct);
|
||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct, int count);
|
||||
|
||||
static void* load_sym(char* symname, void* proxyfunc) {
|
||||
|
||||
|
@ -137,12 +138,52 @@ static unsigned get_rand_seed(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static int socks5_from_env(proxy_data *pd, unsigned int *proxy_count, chain_type *ct) {
|
||||
char *port_string;
|
||||
char *host_string;
|
||||
|
||||
port_string = getenv(PROXYCHAINS_SOCKS5_PORT_ENV_VAR);
|
||||
|
||||
if(!port_string)
|
||||
return 1;
|
||||
|
||||
host_string = getenv(PROXYCHAINS_SOCKS5_HOST_ENV_VAR);
|
||||
|
||||
if(!host_string)
|
||||
return 1;
|
||||
|
||||
memset(pd, 0, sizeof(proxy_data));
|
||||
|
||||
pd[0].ps = PLAY_STATE;
|
||||
|
||||
memset(&pd[0].ip, 0, sizeof(pd[0].ip));
|
||||
|
||||
pd[0].ip.is_v6 = !!strchr(host_string, ':');
|
||||
ip_type* host_ip = &pd[0].ip;
|
||||
|
||||
if(1 != inet_pton(host_ip->is_v6 ? AF_INET6 : AF_INET, host_string, host_ip->addr.v6)) {
|
||||
fprintf(stderr, "proxy %s has invalid value or is not numeric\n", host_string);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pd[0].port = htons((unsigned short) strtol(port_string, NULL, 0));
|
||||
pd[0].pt = SOCKS5_TYPE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void do_init(void) {
|
||||
srand(get_rand_seed());
|
||||
core_initialize();
|
||||
|
||||
int count = 0;
|
||||
|
||||
// if 0, a proxy was set via ENV var (with -p option)
|
||||
if (0 == socks5_from_env(proxychains_pd, &proxychains_proxy_count, &proxychains_ct))
|
||||
count++;
|
||||
|
||||
/* read the config file */
|
||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct, count);
|
||||
DUMP_PROXY_CHAIN(proxychains_pd, proxychains_proxy_count);
|
||||
|
||||
proxychains_write_log(LOG_PREFIX "DLL init: proxychains-ng %s\n", proxychains_get_version());
|
||||
|
@ -278,8 +319,9 @@ static const char* bool_str(int bool_val) {
|
|||
|
||||
#define STR_STARTSWITH(P, LIT) (!strncmp(P, LIT, sizeof(LIT)-1))
|
||||
/* get configuration from config file */
|
||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
|
||||
int count = 0, port_n = 0, list = 0;
|
||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct, int count) {
|
||||
// int count = 0
|
||||
int port_n = 0, list = 0;
|
||||
char buf[1024], type[1024], host[1024], user[1024];
|
||||
char *buff, *env, *p;
|
||||
char local_in_addr_port[32];
|
||||
|
|
25
src/main.c
25
src/main.c
|
@ -63,10 +63,11 @@ static void set_own_dir(const char *argv0) {
|
|||
}
|
||||
}
|
||||
|
||||
#define MAX_COMMANDLINE_FLAGS 2
|
||||
#define MAX_COMMANDLINE_FLAGS 3
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *path = NULL;
|
||||
char *ipport = NULL;
|
||||
char buf[256];
|
||||
char pbuf[256];
|
||||
int start_argv = 1;
|
||||
|
@ -74,6 +75,8 @@ int main(int argc, char *argv[]) {
|
|||
size_t i;
|
||||
const char *prefix = NULL;
|
||||
|
||||
char *token;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--help"))
|
||||
return usage(argv);
|
||||
|
||||
|
@ -89,6 +92,14 @@ int main(int argc, char *argv[]) {
|
|||
else
|
||||
return usage(argv);
|
||||
|
||||
start_argv += 2;
|
||||
} else if(argv[start_argv][1] == 'p') {
|
||||
|
||||
if(start_argv + 1 < argc)
|
||||
ipport = argv[start_argv + 1];
|
||||
else
|
||||
return usage(argv);
|
||||
|
||||
start_argv += 2;
|
||||
}
|
||||
} else
|
||||
|
@ -104,6 +115,18 @@ int main(int argc, char *argv[]) {
|
|||
if(!quiet)
|
||||
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
||||
|
||||
if(ipport) {
|
||||
if(!quiet)
|
||||
fprintf(stderr, LOG_PREFIX "proxy to %s\n", ipport);
|
||||
|
||||
if ((token = strsep(&ipport, ":"))) {
|
||||
setenv(PROXYCHAINS_SOCKS5_HOST_ENV_VAR, token, 1);
|
||||
}
|
||||
if ((token = strsep(&ipport, ":"))) {
|
||||
setenv(PROXYCHAINS_SOCKS5_PORT_ENV_VAR, token, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
|
||||
setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue