@@ -880,6 +880,17 @@ async def test_url(url, rserver):
880
880
print (body .decode ('utf8' , 'ignore' ))
881
881
print (f'============ success ============' )
882
882
883
+ def print_server_started (option , server , print_fn ):
884
+ for s in server .sockets :
885
+ # https://github.com/MagicStack/uvloop/blob/master/uvloop/pseudosock.pyx
886
+ laddr = s .getsockname () # tuple size varies with protocol family
887
+ h = laddr [0 ]
888
+ p = laddr [1 ]
889
+ f = str (s .family )
890
+ ipversion = "ipv4" if f == "AddressFamily.AF_INET" else ("ipv6" if f == "AddressFamily.AF_INET6" else "ipv?" ) # TODO better
891
+ bind = ipversion + ' ' + h + ':' + str (p )
892
+ print_fn (option , bind )
893
+
883
894
def main (args = None ):
884
895
parser = argparse .ArgumentParser (description = __description__ + '\n Supported protocols: http,socks4,socks5,shadowsocks,shadowsocksr,redirect,pf,tunnel' , epilog = f'Online help: <{ __url__ } >' )
885
896
parser .add_argument ('-l' , dest = 'listen' , default = [], action = 'append' , type = proxies_by_uri , help = 'tcp server uri (default: http+socks4+socks5://:8080/)' )
@@ -942,27 +953,36 @@ def main(args = None):
942
953
from . import verbose
943
954
verbose .setup (loop , args )
944
955
servers = []
956
+ def print_fn (option , bind = None ):
957
+ print ('Serving on' , (bind or option .bind ), 'by' , "," .join (i .name for i in option .protos ) + ('(SSL)' if option .sslclient else '' ), '({}{})' .format (option .cipher .name , ' ' + ',' .join (i .name () for i in option .cipher .plugins ) if option .cipher and option .cipher .plugins else '' ) if option .cipher else '' )
945
958
for option in args .listen :
946
- print ('Serving on' , option .bind , 'by' , "," .join (i .name for i in option .protos ) + ('(SSL)' if option .sslclient else '' ), '({}{})' .format (option .cipher .name , ' ' + ',' .join (i .name () for i in option .cipher .plugins ) if option .cipher and option .cipher .plugins else '' ) if option .cipher else '' )
947
959
try :
948
960
server = loop .run_until_complete (option .start_server (vars (args )))
961
+ print_server_started (option , server , print_fn )
949
962
servers .append (server )
950
963
except Exception as ex :
964
+ print_fn (option )
951
965
print ('Start server failed.\n \t ==>' , ex )
966
+ def print_fn (option , bind = None ):
967
+ print ('Serving on UDP' , (bind or option .bind ), 'by' , "," .join (i .name for i in option .protos ), f'({ option .cipher .name } )' if option .cipher else '' )
952
968
for option in args .ulisten :
953
- print ('Serving on UDP' , option .bind , 'by' , "," .join (i .name for i in option .protos ), f'({ option .cipher .name } )' if option .cipher else '' )
954
969
try :
955
970
server , protocol = loop .run_until_complete (option .udp_start_server (vars (args )))
971
+ print_server_started (option , server , print_fn )
956
972
servers .append (server )
957
973
except Exception as ex :
974
+ print_fn (option )
958
975
print ('Start server failed.\n \t ==>' , ex )
976
+ def print_fn (option , bind = None ):
977
+ print ('Serving on' , (bind or option .bind ), 'backward by' , "," .join (i .name for i in option .protos ) + ('(SSL)' if option .sslclient else '' ), '({}{})' .format (option .cipher .name , ' ' + ',' .join (i .name () for i in option .cipher .plugins ) if option .cipher and option .cipher .plugins else '' ) if option .cipher else '' )
959
978
for option in args .rserver :
960
979
if isinstance (option , ProxyBackward ):
961
- print ('Serving on' , option .bind , 'backward by' , "," .join (i .name for i in option .protos ) + ('(SSL)' if option .sslclient else '' ), '({}{})' .format (option .cipher .name , ' ' + ',' .join (i .name () for i in option .cipher .plugins ) if option .cipher and option .cipher .plugins else '' ) if option .cipher else '' )
962
980
try :
963
981
server = loop .run_until_complete (option .start_backward_client (vars (args )))
982
+ print_server_started (option , server , print_fn )
964
983
servers .append (server )
965
984
except Exception as ex :
985
+ print_fn (option )
966
986
print ('Start server failed.\n \t ==>' , ex )
967
987
if servers :
968
988
if args .sys :
0 commit comments