#!/usr/bin/env python # -*- coding: utf-8 -*- # # Send broadcast packets on port UDP_PORT to be easily detected on the network # import time import json import socket #from socket import * UDP_IP = '' UDP_PORT = 4242 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((UDP_IP, 0)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while True: ip_addresses = [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0] hostname = socket.gethostname() data = json.dumps({'id': "robot_detected", 'ip_addresses': ip_addresses, 'hostname': hostname}) sock.sendto(data, ('', UDP_PORT)) time.sleep(2) #[l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0]