Skip to content

Instantly share code, notes, and snippets.

@caioluders
Last active August 31, 2021 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioluders/5a59e1a76aea90705d772b60777a1ab1 to your computer and use it in GitHub Desktop.
Save caioluders/5a59e1a76aea90705d772b60777a1ab1 to your computer and use it in GitHub Desktop.
import json, socket
print('Loading function')
def portScan(ip,ports) :
r = []
for p in ports :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
# returns an error indicator
result = s.connect_ex((ip,p))
if result ==0:
r.append(p)
print("Port {} is open".format(p))
s.close()
return r
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
body = json.loads(event["body"])
result = portScan(body["ip"],body["ports"])
return json.dumps(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment