-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolve_ip.py
executable file
·80 lines (74 loc) · 1.58 KB
/
resolve_ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/user/bin/env python
"""
Resolve the DNS/IP address of a given domain
data returned is in the format:
(name, aliaslist, addresslist)
@filename resolveDNS.py
@version 1.01 (python ver 2.7.3)
@author LoanWolffe
"""
import socket
def getIP(d):
"""
This method returns the first IP address string
that responds as the given domain name
"""
try:
data = socket.gethostbyname(d)
ip = repr(data)
return ip
except Exception:
# fail gracefully!
return False
#
def getIPx(d):
"""
This method returns an array containing
one or more IP address strings that respond
as the given domain name
"""
try:
data = socket.gethostbyname_ex(d)
ipx = repr(data[2])
return ipx
except Exception:
# fail gracefully!
return False
#
def getHost(ip):
"""
This method returns the 'True Host' name for a
given IP address
"""
try:
data = socket.gethostbyaddr(ip)
host = repr(data[0])
return host
except Exception:
# fail gracefully
return False
#
def getAlias(d):
"""
This method returns an array containing
a list of aliases for the given domain
"""
try:
data = socket.gethostbyname_ex(d)
alias = repr(data[1])
#print repr(data)
return alias
except Exception:
# fail gracefully
return False
#
# test it
x = raw_input("Domain name or IP address? > ")
a = getIP(x)
b = getIPx(x)
c = getHost(x)
d = getAlias(x)
print " IP ", a
print " IPx ", b
print " Host ", c
print " Alias ", d