Skip to content

Commit d1881aa

Browse files
committed
Add custom IP support for proxy links
1 parent e62512e commit d1881aa

2 files changed

Lines changed: 96 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ mtproxymax secret setlimits <label> <conns> <ips> <quota> [expires] # Set all l
410410

411411
```bash
412412
mtproxymax port [get|<number>] # Get/set proxy port
413+
mtproxymax ip [get|auto|<address>] # Get/set custom IP for proxy links
413414
mtproxymax domain [get|clear|<host>] # Get/set FakeTLS domain
414415
mtproxymax adtag set <hex> # Set ad-tag
415416
mtproxymax adtag remove # Remove ad-tag

mtproxymax.sh

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ PROXY_DOMAIN="cloudflare.com"
102102
PROXY_CONCURRENCY=8192
103103
PROXY_CPUS=""
104104
PROXY_MEMORY=""
105+
CUSTOM_IP=""
105106
AD_TAG=""
106107
BLOCKLIST_COUNTRIES=""
107108
MASKING_ENABLED="true"
@@ -407,6 +408,11 @@ _PUBLIC_IP_CACHE=""
407408
_PUBLIC_IP_CACHE_AGE=0
408409

409410
get_public_ip() {
411+
# Return custom IP if configured
412+
if [ -n "${CUSTOM_IP}" ]; then
413+
echo "${CUSTOM_IP}"
414+
return 0
415+
fi
410416
local now; now=$(date +%s)
411417
# Return cached IP if less than 5 minutes old
412418
if [ -n "$_PUBLIC_IP_CACHE" ] && [ $(( now - _PUBLIC_IP_CACHE_AGE )) -lt 300 ]; then
@@ -544,6 +550,7 @@ PROXY_DOMAIN='${PROXY_DOMAIN}'
544550
PROXY_CONCURRENCY='${PROXY_CONCURRENCY}'
545551
PROXY_CPUS='${PROXY_CPUS}'
546552
PROXY_MEMORY='${PROXY_MEMORY}'
553+
CUSTOM_IP='${CUSTOM_IP}'
547554
548555
# Ad-Tag (from @MTProxyBot)
549556
AD_TAG='${AD_TAG}'
@@ -595,7 +602,7 @@ load_settings() {
595602
# Whitelist of allowed keys
596603
case "$key" in
597604
PROXY_PORT|PROXY_METRICS_PORT|PROXY_DOMAIN|PROXY_CONCURRENCY|\
598-
PROXY_CPUS|PROXY_MEMORY|AD_TAG|BLOCKLIST_COUNTRIES|\
605+
PROXY_CPUS|PROXY_MEMORY|CUSTOM_IP|AD_TAG|BLOCKLIST_COUNTRIES|\
599606
MASKING_ENABLED|MASKING_HOST|MASKING_PORT|\
600607
TELEGRAM_ENABLED|TELEGRAM_BOT_TOKEN|TELEGRAM_CHAT_ID|\
601608
TELEGRAM_INTERVAL|TELEGRAM_ALERTS_ENABLED|TELEGRAM_SERVER_LABEL|\
@@ -2897,7 +2904,7 @@ load_tg_settings() {
28972904
local key="${BASH_REMATCH[1]}" val="${BASH_REMATCH[2]}"
28982905
case "$key" in
28992906
PROXY_PORT|PROXY_DOMAIN|PROXY_METRICS_PORT|PROXY_CONCURRENCY|\
2900-
PROXY_CPUS|PROXY_MEMORY|MASKING_ENABLED|MASKING_HOST|MASKING_PORT|\
2907+
PROXY_CPUS|PROXY_MEMORY|CUSTOM_IP|MASKING_ENABLED|MASKING_HOST|MASKING_PORT|\
29012908
AD_TAG|BLOCKLIST_COUNTRIES|AUTO_UPDATE_ENABLED|\
29022909
TELEGRAM_ENABLED|TELEGRAM_BOT_TOKEN|TELEGRAM_CHAT_ID|\
29032910
TELEGRAM_INTERVAL|TELEGRAM_SERVER_LABEL|TELEGRAM_ALERTS_ENABLED)
@@ -2911,6 +2918,10 @@ load_tg_settings() {
29112918
_TG_IP_CACHE=""
29122919
_TG_IP_CACHE_AGE=0
29132920
get_cached_ip() {
2921+
# Return custom IP if configured
2922+
if [ -n "${CUSTOM_IP}" ]; then
2923+
echo "${CUSTOM_IP}"; return 0
2924+
fi
29142925
local now; now=$(date +%s)
29152926
if [ -n "$_TG_IP_CACHE" ] && [ $(( now - _TG_IP_CACHE_AGE )) -lt 300 ]; then
29162927
echo "$_TG_IP_CACHE"; return 0
@@ -3542,6 +3553,22 @@ run_installer() {
35423553
fi
35433554
fi
35443555

3556+
# Custom IP
3557+
echo ""
3558+
local _detected_ip
3559+
_detected_ip=$(CUSTOM_IP="" get_public_ip)
3560+
echo -e " ${BOLD}Server IP${NC} ${DIM}(used in proxy links)${NC}"
3561+
echo -en " ${DIM}Detected: ${_detected_ip:-unknown} — Enter custom IP or press Enter [${_detected_ip:-auto}]:${NC} "
3562+
local ip_input
3563+
read -r ip_input
3564+
if [ -n "$ip_input" ]; then
3565+
if [[ "$ip_input" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$ip_input" =~ ^[0-9a-fA-F:]+$ ]]; then
3566+
CUSTOM_IP="$ip_input"
3567+
else
3568+
log_warn "Invalid IP address, using auto-detected"
3569+
fi
3570+
fi
3571+
35453572
# Domain
35463573
echo ""
35473574
echo -e " ${BOLD}FakeTLS domain${NC} ${DIM}(your proxy will look like HTTPS to this site)${NC}"
@@ -3900,6 +3927,7 @@ show_cli_help() {
39003927
echo ""
39013928
echo -e " ${BOLD}Configuration:${NC}"
39023929
echo -e " ${GREEN}port${NC} [get|<number>] Show or change proxy port"
3930+
echo -e " ${GREEN}ip${NC} [get|auto|<address>] Show, reset, or set custom IP for links"
39033931
echo -e " ${GREEN}domain${NC} [get|clear|<host>] Show, clear, or change FakeTLS domain"
39043932
echo -e " ${GREEN}adtag${NC} [set <hex>|remove|view] Manage ad-tag"
39053933
echo -e " ${GREEN}geoblock${NC} [add|remove|list|clear] Manage geo-blocking"
@@ -4112,6 +4140,38 @@ cli_main() {
41124140
fi
41134141
;;
41144142

4143+
ip)
4144+
load_settings
4145+
local ip_arg="$1"
4146+
case "$ip_arg" in
4147+
""|get)
4148+
if [ -n "${CUSTOM_IP}" ]; then
4149+
echo "${CUSTOM_IP} (custom)"
4150+
else
4151+
echo "$(get_public_ip) (auto-detected)"
4152+
fi
4153+
return 0
4154+
;;
4155+
auto|clear)
4156+
check_root
4157+
CUSTOM_IP=""
4158+
save_settings
4159+
log_success "IP reset to auto-detect ($(CUSTOM_IP="" get_public_ip))"
4160+
;;
4161+
*)
4162+
check_root
4163+
if [[ "$ip_arg" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$ip_arg" =~ ^[0-9a-fA-F:]+$ ]]; then
4164+
CUSTOM_IP="$ip_arg"
4165+
save_settings
4166+
log_success "IP set to ${ip_arg}"
4167+
else
4168+
log_error "Invalid IP address: ${ip_arg}"
4169+
return 1
4170+
fi
4171+
;;
4172+
esac
4173+
;;
4174+
41154175
domain)
41164176
load_settings
41174177
local new_domain="$1"
@@ -4831,6 +4891,7 @@ show_settings_menu() {
48314891
draw_header "SETTINGS"
48324892
echo ""
48334893
echo -e " ${BOLD}Port:${NC} ${PROXY_PORT}"
4894+
echo -e " ${BOLD}IP:${NC} ${CUSTOM_IP:-$(get_public_ip) ${DIM}(auto)${NC}}"
48344895
echo -e " ${BOLD}Domain:${NC} ${PROXY_DOMAIN}"
48354896
echo -e " ${BOLD}CPU:${NC} ${PROXY_CPUS:-unlimited}"
48364897
echo -e " ${BOLD}Memory:${NC} ${PROXY_MEMORY:-unlimited}"
@@ -4840,12 +4901,13 @@ show_settings_menu() {
48404901
echo -e " ${BOLD}Engine:${NC} telemt v$(get_telemt_version)"
48414902
echo ""
48424903
echo -e " ${DIM}[1]${NC} Change port"
4843-
echo -e " ${DIM}[2]${NC} Change domain"
4844-
echo -e " ${DIM}[3]${NC} Change resources (CPU/RAM)"
4845-
echo -e " ${DIM}[4]${NC} Toggle traffic masking"
4846-
echo -e " ${DIM}[5]${NC} Set ad-tag"
4847-
echo -e " ${DIM}[6]${NC} Toggle auto-update"
4848-
echo -e " ${DIM}[7]${NC} Engine Management"
4904+
echo -e " ${DIM}[2]${NC} Change IP"
4905+
echo -e " ${DIM}[3]${NC} Change domain"
4906+
echo -e " ${DIM}[4]${NC} Change resources (CPU/RAM)"
4907+
echo -e " ${DIM}[5]${NC} Toggle traffic masking"
4908+
echo -e " ${DIM}[6]${NC} Set ad-tag"
4909+
echo -e " ${DIM}[7]${NC} Toggle auto-update"
4910+
echo -e " ${DIM}[8]${NC} Engine Management"
48494911
echo -e " ${DIM}[0]${NC} Back"
48504912

48514913
local choice
@@ -4869,6 +4931,26 @@ show_settings_menu() {
48694931
press_any_key
48704932
;;
48714933
2)
4934+
local _det_ip; _det_ip=$(CUSTOM_IP="" get_public_ip)
4935+
echo -e " ${DIM}Detected: ${_det_ip:-unknown}${NC}"
4936+
echo -en " ${BOLD}Custom IP [${CUSTOM_IP:-auto}]:${NC} "
4937+
local ip; read -r ip
4938+
if [ "$ip" = "auto" ] || [ "$ip" = "clear" ]; then
4939+
CUSTOM_IP=""
4940+
save_settings
4941+
log_success "IP reset to auto-detect (${_det_ip})"
4942+
elif [ -n "$ip" ]; then
4943+
if [[ "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$ip" =~ ^[0-9a-fA-F:]+$ ]]; then
4944+
CUSTOM_IP="$ip"
4945+
save_settings
4946+
log_success "IP set to ${ip}"
4947+
else
4948+
log_error "Invalid IP address"
4949+
fi
4950+
fi
4951+
press_any_key
4952+
;;
4953+
3)
48724954
echo -e " ${DIM}[1] cloudflare.com [2] google.com [3] microsoft.com [4] Custom${NC}"
48734955
local d; d=$(read_choice "Choice" "1")
48744956
local _domain_changed=true
@@ -4900,7 +4982,7 @@ show_settings_menu() {
49004982
fi
49014983
press_any_key
49024984
;;
4903-
3)
4985+
4)
49044986
echo -en " ${BOLD}CPU cores [${PROXY_CPUS:-unlimited}]:${NC} "
49054987
local c; read -r c
49064988
local _res_changed=false
@@ -4932,7 +5014,7 @@ show_settings_menu() {
49325014
fi
49335015
press_any_key
49345016
;;
4935-
4)
5017+
5)
49365018
[ "$MASKING_ENABLED" = "true" ] && MASKING_ENABLED="false" || MASKING_ENABLED="true"
49375019
save_settings
49385020
log_success "Traffic masking: ${MASKING_ENABLED}"
@@ -4943,7 +5025,7 @@ show_settings_menu() {
49435025
fi
49445026
press_any_key
49455027
;;
4946-
5)
5028+
6)
49475029
echo -en " ${BOLD}Ad-tag (32 hex chars, or 'remove'):${NC} "
49485030
local at; read -r at
49495031
if [ "$at" = "remove" ]; then
@@ -4965,13 +5047,13 @@ show_settings_menu() {
49655047
fi
49665048
press_any_key
49675049
;;
4968-
6)
5050+
7)
49695051
[ "$AUTO_UPDATE_ENABLED" = "true" ] && AUTO_UPDATE_ENABLED="false" || AUTO_UPDATE_ENABLED="true"
49705052
save_settings
49715053
log_success "Auto-update: ${AUTO_UPDATE_ENABLED}"
49725054
press_any_key
49735055
;;
4974-
7) show_engine_menu ;;
5056+
8) show_engine_menu ;;
49755057
0|"") return ;;
49765058
*) ;;
49775059
esac

0 commit comments

Comments
 (0)