Back to Browse

Python Scripting Tutorial: Retrieve Network Info and Send Messages using Twilio API

43 views
Aug 14, 2023
6:18

**Disclaimer: Responsible and Ethical Scripting Practices** This video is intended to provide educational content on scripting techniques and their applications. The scripts discussed in this video are meant to be used responsibly and ethically. The purpose of these scripts is to demonstrate how to retrieve network information and interact with APIs for legitimate purposes. Please note the following: 1. **Educational Use Only**: The information and scripts provided in this video are for educational purposes only. They are not intended to encourage or support any form of malicious or unauthorized activities. 2. **Respect Privacy and Authorization**: Always obtain proper authorization before running any scripts on systems or networks that you do not own. Respecting the privacy and security of others' systems is essential. 3. **Legal Compliance**: Misusing scripts for unauthorized activities can lead to legal consequences. Make sure to adhere to applicable laws, regulations, and ethical standards. 4. **Positive Learning**: We encourage you to learn from the scripting techniques demonstrated in this video. Apply your knowledge to enhance your understanding of scripting, network operations, and API interactions in positive and constructive ways. 5. **Promote Ethical Behavior**: Use your skills to contribute positively to the technical community. Be mindful of the potential impact of your actions and always prioritize responsible usage. Remember, responsible scripting is about learning, improving your skills, and using your knowledge for ethical purposes. Thank you for joining us in promoting a positive and responsible approach to technology. ----------------------------------------------------------------------------------------------------------------- Python script: import socket from twilio.rest import Client # Replace with your Twilio Account SID and Auth Token TWILIO_ACCOUNT_SID = 'YOUR_TWILIO_ACCOUNT_SID' TWILIO_AUTH_TOKEN = 'YOUR_TWILIO_AUTH_TOKEN' # Replace with your Twilio phone number and your personal phone number TWILIO_PHONE_NUMBER = 'YOUR_TWILIO_PHONE_NUMBER' YOUR_PHONE_NUMBER = 'YOUR_RECIPIENT_PHONE_NUMBER' def get_ip_and_hostname(): # Get the local hostname hostname = socket.gethostname() # Get the IP address of the local hostname ip_address = socket.gethostbyname(hostname) return hostname, ip_address def check_port(host, port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) # Set a timeout for the connection attempt try: sock.connect((host, port)) return f"Port {port} is open" except (socket.timeout, ConnectionRefusedError): return f"Port {port} is closed" finally: sock.close() def send_message(message): client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) client.messages.create( body=message, from_=TWILIO_PHONE_NUMBER, to=YOUR_PHONE_NUMBER ) if __name__ == "__main__": hostname, ip_address = get_ip_and_hostname() ports_to_check = [80, 443, 22, 3389] # Replace with the ports you want to check port_status = [] for port in ports_to_check: status = check_port(ip_address, port) port_status.append(status) message = f"Hostname: {hostname}\nIP address: {ip_address}\nPort Status:\n" message += "\n".join(port_status) try: send_message(message) print("Message sent successfully!") except Exception as e: print(f"An error occurred: {e}")

Download

0 formats

No download links available.

Python Scripting Tutorial: Retrieve Network Info and Send Messages using Twilio API | NatokHD