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