-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanner_grabber.py
More file actions
28 lines (24 loc) · 1.15 KB
/
banner_grabber.py
File metadata and controls
28 lines (24 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python3
import socket
# Function to grab the banner from a specific IP and port
def retBanner(ip, port):
try:
socket.setdefaulttimeout(2) # Set a timeout for the socket connection
with socket.socket() as sock:
sock.connect((ip, port)) # Connect to the target IP and port
banner = sock.recv(1024) # Receive up to 1024 bytes from the socket
return banner
except:
return # Return None if connection fails or times out
def main():
ip = input("Enter Target IP: ") # Prompt user for the target IP address
for port in range(1, 65353): # Scan ports from 1 to 65352
banner = retBanner(ip, port) # Attempt to grab the banner for each port
if banner:
try:
banner_str = banner.decode('utf-8', errors='replace').strip() # Decode banner to string
except:
banner_str = str(banner) # Fallback to string representation if decoding fails
print(f"[+] {ip}/{port} - {banner_str}") # Print the banner information
if __name__ == "__main__":
main() # Run the main function if the script is executed directly