获取当前服务器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'

 

posted @ 2020-07-08 16:52  muyue123  阅读(318)  评论(0编辑  收藏  举报