[Python] 호스트네임 가져오기

반응형
반응형

 

 

1. import socket -> gethostname()

 

import socket
 
def get_hostname():
    host = socket.gethostname()
    print('HOST:' + host)

if __name__ == '__main__':
    get_hostname()

 

 

2. import playform -> uname()[1]

 

import platform

def get_hostname():
    host=platform.uname()[1]
    print('HOST:' + host)

if __name__ == '__main__':
    get_hostname()

 

 

3. import os -> uname()[1]

 

import os

def get_hostname():
    host=os.uname()[1]
    print('HOST:' + host)

if __name__ == '__main__':
    get_hostname()

 

 

[출력]

세 가지 방법 모두 출력 결과 동일

[root@linux-1 bin]# python gethostname.py 
HOST:linux-1
반응형

댓글

Designed by JB FACTORY

loading