Skip to content

Instantly share code, notes, and snippets.

@hmert
Created April 21, 2011 15:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hmert/934734 to your computer and use it in GitHub Desktop.
Save hmert/934734 to your computer and use it in GitHub Desktop.
python port scanner
#!/usr/bin/env python
from socket import *
if __name__ == '__main__':
target = raw_input('IP: ')
targetIP = gethostbyname(target)
#scan reserved ports
for i in range(20, 1025):
s = socket(AF_INET, SOCK_STREAM)
result = s.connect_ex((targetIP, i))
if(result == 0) :
print 'Port %d:' % (i,)
s.close()
#./scanner.py
Enter host to scan: localhost
Starting scan on host 192.168.1.1
Port 80: OPEN
Port 445: OPEN
@anejckl
Copy link

anejckl commented Oct 19, 2020

hi, im new to programming so i was wondering how to fix this syntax error
image

@noobprogammier
Copy link

noobprogammier commented Oct 21, 2020

@anejck007, that is a python2 programming, you should put print ("Port %d: ") % (i,), or ('port %d: "), hope i was helful <3

@noobprogammier
Copy link

print('Hello World')

@noobprogammier
Copy link

example

@noobprogammier
Copy link

or in python2 - print 'hello, world'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment