Last active
August 31, 2021 05:57
-
-
Save caioluders/5a59e1a76aea90705d772b60777a1ab1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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