-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathip.py
63 lines (46 loc) · 1016 Bytes
/
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
#!/usr/bin/python
import sys
import socket
def getDec(parts):
dec = 0
w = 1
for i in range(len(parts)):
dec += int(parts[i]) * (256 ** ((3 - i)))
return dec
def getHex(parts):
hx = ''
for i in range(len(parts)):
if i != 0: hx += '.'
hx += hex(int(parts[i]))
return hx
def getOct(parts):
ot = ''
for i in range(len(parts)):
if i != 0: ot += '.'
ot += oct(int(parts[i]))
return ot
def getBin(parts):
bi = ''
for i in range(len(parts)):
if i != 0: bi += '.'
bi += bin(int(parts[i]))
return bi
if len(sys.argv) < 2:
host = raw_input('input host:')
else:
host = sys.argv[1]
ip = socket.gethostbyname(host)
print "IP Address:", ip
print
parts = ip.split('.')
dec = getDec(parts)
print "Decimal IP:", dec
print
hx = getHex(parts)
print "Hex IP:", hex(dec)
print "Dotted Hex IP:", hx
print
print "Oct IP", oct(dec)
print "Dotted Oct IP:", getOct(parts)
print
print "xip.io:", ip + ".xip.io"