I have a machine at home, dial-up Internet access, an independent IP, and many services. What should I do if I want to access it at any time outside? Remember the connected IP when you go out? If the connection is disconnected, the IP will change after automatic reconnection, so the solution may be to use the "Peanut Shell" software. Peanut Shell also has a Linux version, which is indeed an option, but it is equivalent to publishing your IP to the Internet. Assume that you are not very confident about your own security (besides, you don’t know whether Peanut Shell has collected any information about you) , and your purpose is only to use it on a small scale (for example, just you, your family or a few close friends), then this dynamic IP can be spread through personal emails. I have simply explored two solutions. One One is based on knemo+kmail, and the other is based on udev+mail+exim4. Here is a brief introduction:
1. knemo + kmmail
Knemo is a network monitoring software under kde and supports event triggering. Kmail is an email client under kde and supports dcop script calling. The configuration steps are as follows:
Create a script that automatically obtains a dial-up connection IP and sends it via kmail:
#!/bin/bash
FROM="none"
TO="[email protected]"
CC="[email protected]"
BCC=""
SUBJECT="Today's PPP address"
sleep 10s
MESSAGE=`/sbin/ifconfig /bin/sed -e '/PtP/!d' -e 's/^[[:space:]]* inet addr://g' -e 's/[[:space :]]*PtP:.*Mask:.*$//g'`
ATTACHMENT="[] []"
dcop kmail MailTransportServiceIface "sendMessage(QString, QString, QString, QString, QString, QString, KURL::List)" "$FROM" "$TO" "$CC" "$BCC" "$SUBJECT" "$MESSAGE" $ATTACHMENT
Then use it as the corresponding executed program in the notification configured by knemo. The knemo configuration is on the kcontrol -> internet&network -> network monitor -> Misc panel.
2. udev + mail + exim4
The first method is very simple, but it requires you to use kde and keep your desktop open at all times (because you need knemo and kmail). The second method is to obtain the hardware changes of the kernel. In case of disconnection, reconnect, / It is triggered when the device files below sys/ change, and does not depend on X and desktop systems.
I won’t go into the configuration of exim4 here, just check it out online.
The corresponding sending script (/XXXXX/ppp-address.sh) is modified as follows:
#!/bin/bash
FROM="none"
TO="[email protected]"
CC="[email protected]"
BCC=""
SUBJECT="Today's PPP address"
sleep 10s
MESSAGE=`/sbin/ifconfig /bin/sed -e '/PtP/!d' -e 's/^[[:space:]]* inet addr://g' -e 's/[[:space :]]*PtP:.*Mask:.*$//g'`
echo "$MESSAGE" /usr/bin/mail -s "$SUBJECT" -c "$CC" -b "$BCC" "$TO"
Add udev rules: /etc/udev/rules.d/ Next add a rule file such as z100_ppp_ip_letter.rules with the following content:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="ppp[0-9]", RUN+="/XXXXX/ppp-address.sh"