Skip to content

Instantly share code, notes, and snippets.

@meise
Created July 20, 2015 14:24
Show Gist options
  • Save meise/c1a388b5c8a3dc229f6c to your computer and use it in GitHub Desktop.
Save meise/c1a388b5c8a3dc229f6c to your computer and use it in GitHub Desktop.
(raspberry pi) broadcast ip addresses after boot
#!/usr/bin/env ruby
# encoding: utf-8
require 'socket'
hostname = Socket.gethostname
socket = UDPSocket.new
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
10.times.each do
ip_addresses = Socket.ip_address_list.map(&:ip_address).join(', ')
socket.send("#{hostname}: #{ip_addresses}", 0, "255.255.255.255", 4223)
sleep 10
end
socket.close
exit 0
# /etc/systemd/system/broadcast_ip.service
[Unit]
Description=Broadcast ip addresses
Requires=network-online.target
[Service]
ExecStart=/usr/local/bin/broadcast_ip.rb
KillMode=process
RemainAfterExit=no
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment