瀏覽代碼

Adding DNS Lookup Python Schnippets

Adding IP to Hostname and Hostname to IP via the socket library.
master
Nate Bohman 5 年之前
父節點
當前提交
76a11e96cc
共有 1 個文件被更改,包括 28 次插入0 次删除
  1. +28
    -0
      python_utils/dns_lookup.py

+ 28
- 0
python_utils/dns_lookup.py 查看文件

@@ -0,0 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket

def get_hostname(host_or_ip):
host_or_ip = socket.getfqdn(host_or_ip)

try:
return socket.gethostbyaddr(host_or_ip)[0]
except socket.gaierror:
return False

def get_aliases(host_or_ip):
host_or_ip = socket.getfqdn(host_or_ip)

try:
return socket.gethostbyaddr(host_or_ip)[1]
except socket.gaierror:
return False

def get_ip_addrs(host_or_ip):
host_or_ip = socket.getfqdn(host_or_ip)

try:
return socket.gethostbyaddr(host_or_ip)[2]
except socket.gaierror:
return False

Loading…
取消
儲存