Files
gists/codegrab/smtpbanner.py
TKE 6fddcd2a43 Added some Tools
imphash    :  generates a Virustotal compatible IMPHASH for a binary
ltop       :  does 'sort|uniq -c' but with live update in ncurses
smtpbanner :  grabs smtp banner
uniq       :  like uniq but does not need sorting.
uniqrs     :  same as uniq but written in Rust
2023-05-04 08:10:52 +02:00

36 lines
971 B
Python

#!/usr/bin/env python
# banner.py
import sys
import socket
import argparse
def grab(ip, port):
"""Connects to the specified IP and port, retrieves data and returns the decoded response."""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
sock.settimeout(5) # Set a timeout of 5 seconds
sock.connect((ip, port))
ret = sock.recv(1024)
return ret.strip().decode()
except socket.error as e:
return f"Connection error: {e}"
finally:
sock.close()
def main():
parser = argparse.ArgumentParser(description="Retrieve banner information from the specified IP and port.")
parser.add_argument("ip", help="The target IP address")
parser.add_argument("-p", "--port", type=int, default=25, help="The target port (default: 25)")
args = parser.parse_args()
ip = args.ip
port = args.port
print(grab(ip, port))
if __name__ == "__main__":
main()