Jump to content
Ganav

[TUT] Un substituent partial pentru dns dinamic

Recommended Posts

Posted (edited)

Acest tutorial prezinta un mod de a obtine adresa unei statii ce foloseste servicii dhcp. Pe statia respectiva descarcam urmatorul script:

IPmailer.sh


#!/bin/bash

wget --header="Accept: text/html" --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0" http://checkip.dyndns.org/ -O ip_file
# Resetam fisierul de e-mail deoarece adresa IP se schimba periodic, deci si continutul acestuia
echo "" > mail_file
# Setam adresa e-mail sursa
echo "From: \"User Name\" <username@gmail.com>" > mail_file
# Setam adresa e-mail destinatie
echo "To: \"Destinatie\" <destinatie@example.com>" >> mail_file
echo "Subject: Adresa statiei de acasa" >> mail_file
# Filtram adresa IP curenta a statiei aflata la distanta(remote)
echo `cat ip_file | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"` >> mail_file
# Trimitem un e-mail cu adresa respectiva
curl --url "smtps://smtp.gmail.com:465" --ssl-reqd \
--mail-from "username@gmail.com" --mail-rcpt "destinatie@example.com" \
--upload-file mail_file --user "username@gmail.com:password" --insecure

Acum trebuie sa acordam permisiuni de scriere pentru fisier:

chmod +x IPmailer.sh

Adresele "User Name" si "destinatie" sunt adresele unor conturi gmail cunoscute.

Acum dorim sa rulam acest script periodic, din ora in ora:


sudo crontab -e
0 * * * * cd folderul_care_contine_IPmail.sh && ./IPmail.sh

De pe statia noastra putem sa ne logam pe destinatie@gmail.com si sa verificam din ora in ora IP-ul masinii aflate la distanta.

Intrucat parola apare in clar in acest script este recomandata folosirea unui cont cu importanta redusa astfel incat compromiterea lui sa nu aduca mari pierderi.

Edited by Ganav

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...