Created
July 20, 2015 14:24
-
-
Save meise/c1a388b5c8a3dc229f6c to your computer and use it in GitHub Desktop.
(raspberry pi) broadcast ip addresses after boot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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