Skip to content

Instantly share code, notes, and snippets.

@p208p2002
Created March 4, 2019 05:29
Show Gist options
  • Select an option

  • Save p208p2002/85eec17297112e1a82090c1ba2c4e9f8 to your computer and use it in GitHub Desktop.

Select an option

Save p208p2002/85eec17297112e1a82090c1ba2c4e9f8 to your computer and use it in GitHub Desktop.
import socket
def get_remote_machine_info():
remote_host = 'www.python.org' #目標host
try: #使用try except做例外處理
print ("IP address of %s: %s" %(remote_host, socket.gethostbyname(remote_host))) #印出結果
except socket.error as err_msg: #如果發生錯誤
print ("%s: %s" %(remote_host, err_msg)) #印出錯誤訊息
if __name__ == '__main__':
get_remote_machine_info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment