获取当前服务器IP和机器名
import socket #获取本机电脑名 myname = socket.getfqdn(socket.gethostname()) #获取本机ip myaddr = socket.gethostbyname(myname) print(myname) print(myaddr)
import socket hostname = socket.gethostname() # 获取当前主机名 if hostname == 'ip-172-10-2-70': db_server = '172.10.2.70' db_name = 'trancare_spd_q' else: db_server = '10.0.8.217' db_name = 'trancare_spd_q_india'