Hi,
I'm trying to use launchd to detect whether certain ports are opened
and if they are then to take some appropriate action, e.g. close the
port or, worst case scenario, down the whole net connection. Apparently,
force closing a port is not possible without killing the offending binary so
the next best option was to down the network connection.
In this particular example, the LaunchDaemon is supposed to monitor
whether a list of ports are activated, whilst the network state is true, and
if so then close the network connection.
Unfortunately, the 'Sockets -> Listeners' properties create ports that
meets the condition to down the network connection and not 'if' they are
created. Therefore, as soon as it is deployed, the network connection is
taken offline.
Due to the lack of documentation regarding launchd, I've not been able
to even determine if this approach is even possible.
Can anyone help?
A.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disable</key>
<false/>
<key>Label</key>
<string>net.localhost.ports</string>
<key>Program</key>
<string>/sbin/ifconfig</string>
<key>ProgramArguments</key>
<array>
<string>ifconfig</string>
<string>en0</string>
<string>down</string>
</array>
<key>KeepAlive</key>
<dict>
<key>NetworkState</key>
<true/>
</dict>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<array>
<dict>
<key>SockServiceName</key>
<string>8787</string>
<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>31337</string>
<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>31337</string>
<key>SockType</key>
<string>dgram</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>31338</string>
<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>31338</string>
<key>SockType</key>
<string>dgram</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>54320</string>
<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>54321</string>
<key>SockType</key>
<string>stream</string>
</dict>
<dict>
<key>SockServiceName</key>
<string>54321</string>
<key>SockType</key>
<string>dgram</string>
</dict>
</array>
</dict>
</dict>
</plist>
---------- Post updated at 07:33 PM ---------- Previous update was at 03:15 PM ----------
Additional...
Just got off the forum at macosxhints.com and apparently
launchd can't detect whether a connection to a socket/port
has been made making my quick-fix approach futile.
Unless someone knows any hacks.
A.