H1 Programming

the art of programming

IsAlive (Python)

This script asks for a target host and port number and then tells you whether you can connect to that specific port.

#! /usr/bin/env python

#IsAlive - This script checks whether the target host is online or not
#This basically a test script, use how you want
#Written by DarkMunk for H1 Programming Python Snippets section

import socket
import sys
mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
print "Enter host IP"
hostIP = raw_input()
print "Enter host port"
hostPort = int(raw_input())

try:
mySocket.connect ( ( hostIP, hostPort ) )
print "Host Online"
mySocket.close
except:
print "Host not online"