Skip to content

Instantly share code, notes, and snippets.

@kota65535
Last active November 23, 2015 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kota65535/fb66270cf030ea84bad3 to your computer and use it in GitHub Desktop.
Save kota65535/fb66270cf030ea84bad3 to your computer and use it in GitHub Desktop.
SSDP:Discoverに利用するブロードキャストアドレスの経路追加 (Mac版)
#!/bin/bash
set -u
export LANG="C"
function usage() {
cat <<EOT
Usage: bash ${0##*/} <interface-name>
EOT
}
# 引数チェック
if [ $# -ne 1 ]; then usage && exit 1; fi
# SSDP discoverで使用するブロードキャストアドレス
SSDP_ADDR=239.255.255.250
# 所定のインターフェース経由の経路があるか調べる
route get ${SSDP_ADDR} | grep -q "interface: $1"
if [ $? -eq 0 ]; then
echo 'Route already configured.'
exit 0
fi
# 所定のインターフェース経由の経路を追加する
route add -host ${SSDP_ADDR} -interface $1
if [ $? -ne 0 ]; then
echo "Failed to add route to host ${SSDP_ADDR} via $1"
exit 1
fi
# 最後に再度確認
route get ${SSDP_ADDR} | grep -q "interface: $1"
if [ $? -eq 0 ]; then
echo "Something goes wrong!"
exit 2
fi
echo 'Route added successfully.'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment