Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # PortScanner.py
- # Author: Abdul Fatir
- # E-Mail: abdulfatirs@gmail.com
- from socket import *
- HostName = raw_input("Host Name: ")
- try:
- # gethostbyname(HostName) returns the IPv4 address of a website
- IPaddress = gethostbyname(HostName)
- except:
- print "[-] Could not find host."
- quit()
- portstring = raw_input("Ports (separated by commas):")
- ports = portstring.split(",")
- print "\n[*] Scan results for "+HostName+" ("+IPaddress+"):"
- # setdefaulttimeout(1) sets the waiting time for website response to 1 seconds. This may result in closed port even though the port may be open if it takes more than 1 second.
- setdefaulttimeout(1)
- for port in ports:
- try:
- connection = socket(AF_INET,SOCK_STREAM)
- # socket.connect((IP,PORT)) connect to the IP at given port.
- connection.connect((IPaddress,int(port)))
- connection.send('hello\r\n')
- # socket.recv(BUFFER_SIZE) receives the server response
- data = connection.recv(8)
- # If we have reached this far that means the port is open.
- print "\t[+] "+port+"/tcp open"
- except:
- print "\t[-] "+port+"/tcp closed"
- finally:
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement