Skip to main content

Python & BASH Script to flag change of External IP address

This script reads the external IP address, stored in file ext_ip_add.txt (full path), then gets the new external IP address and compares the two, then overwrites previous stored address. Replace LT with proper less than sign and GT with greater than sign. Following cron job pipes output to a text to speech converter.

#!usr/bin/python
#
# Program gets your external IP address
#
# This program reads the title from
# myip.dk website and prints out from
# 12th char after <
#
# Prog checks for change in ip address
#
# The ip address is written to file
# ext_ip_add.txt (overwritten)
#
# Version 1.0 Geoff Robinson July 09

fileobject1=open('/home/geoff/python/ext_ip_add.txt','r')
oldipaddress = fileobject1.readline()
fileobject1.close


import urllib

url = urllib.URLopener()
resp = url.open('http://myip.dk')
html = resp.read()
start = html.find("LTtitleGT") + 12
end = html.find("LT/titleGT")


newipaddress = html[start:end].strip()

if newipaddress == oldipaddress:
print 'your external inter net address has not changed'
else:
print 'you have a new external inter net address, your'
print newipaddress

# This section writes the external
# IP address to ext_ip_add.txt file

fileobject=open('/home/geoff/python/ext_ip_add.txt','w')
fileobject.write(html[start:end])
fileobject.close()

OR (simpler bash script)
#!/bin/bash
#
#  Script to write external ip address to syslog.
#  Note this script passes environment variable
back to parent shell so run with cmd
#  . ./my_address.

#


IP_ADD=`/usr/bin/curl -s http://ip.nefsc.noaa.gov/ | /bin/grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"`
NEW_IP=$IP_ADD
if [ $OLD_IP = $NEW_IP ]; then
   echo "no change - external ip is $IP_ADD" | logger
else
   echo " New ip address is $NEW_IP " | logger
   export OLD_IP=$NEW_IP
fi

Comments

Popular posts from this blog

Digital Bandpass Filter FIR design - Python

The python code generates the Finite Impulse Response (FIR) filter coefficients for a lowpass filter (LPF) at 10 (Hz) cut off using firwin from scipy.  A highpass filter is then created by subtracting the lowpass filter output(s) from the output of an allpass filter. To do this the coefficients of the LPF are multiplied by -1 and 1 added to the centre tap (to create the allpass filter with subtraction). A second LPF is then created with a cutoff at 15 (Hz) and the bandpass filter formed by addition of the LPF and HPF coefficients. The program also generates a test sine wave of a given amplitude and power and to this noise from a Normal distribution is added.  The graph below shows the signal and nois, and the signal (green) after filtering. The input snr is approximately 3dB. The frequency response below shows the passband centered on 12.5 (Hz), the Nyquist frequency is 50 (Hz). from numpy import cos, sin, pi, absolute, arange from numpy.random import normal fr...

GNU Radio Waterfall and CW Filter

The following GNU radio application adds a waterfall spectrogram to the previous CW filter program. The plot show 4 CW signals in the audio band (lower sideband) at 7023 kHz. The 700Hz signal is filtered and output to the laptop headphones by the CW bandpass filter. The frequency display is shown after the script which is as follows: #!/usr/bin/env python from gnuradio import gr from gnuradio import audio from lpf_bpf_class import Bandpass from gnuradio.qtgui import qtgui from PyQt4 import QtGui import sys, sip     class cw_filter(gr.top_block):     def __init__(self):         gr.top_block.__init__(self)           sample_rate = 44100         out_rate = 8000         kaiser = Bandpass()         cw_flr = gr.fir_filter_fff(1, kaiser.bpftaps)         decimate = int...

QUISK SDR 40 metre RX

To test the previous GNU radio apps and evaluate the linux SDR QUISK software, the following 7MHz SDR was quickly assembled from available parts.  The heart of the hardware is the modulator section of a Marconi QPSK modem using Watkins Johnson M6E mixers with a 90 deg phase shift circuit modified for the xtal frequency of 7035kHz. Using the Softrock .quisk_conf.py file for QUISK with: fixed_vfo_freq = 7035000        sample_rate = 96000 The following daytime spectrograph was obtained on 40 metres. The SDR hardware (90% not used, including the 741 or TL081 op amps as they were noisy + insufficient gain-BW). The PC was a Toshiba Satellite L650 laptop with Ubuntu 11.10 OS.