-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.py
35 lines (25 loc) · 883 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
import socket # for sockets
# create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket Created'
import socket # for sockets
import sys # for exit
try:
# create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
sys.exit();
print 'Socket Created'
host = "http://10.200.216.65/"
port = 22
try:
remote_ip = socket.gethostbyname(host)
except socket.gaierror:
# could not resolve
print 'Hostname could not be resolved. Exiting'
sys.exit()
print 'Ip address of ' + host + ' is ' + remote_ip
# Connect to remote server
s.connect((remote_ip, port))
print 'Socket Connected to ' + host + ' on ip ' + remote_ip