Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added port checker and utc internet clock

  • Loading branch information...
commit 9da4649b56ebf7430414f02bfa7ff4342220c797 1 parent 26a73e4
@DungFu authored
Showing with 102 additions and 0 deletions.
  1. +67 −0 clock.sh
  2. +35 −0 ports.sh
View
67 clock.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+# This script is a clock that will either get time from the local machine
+# or from a remote server (it will randomly pick from the list at the beginning of the file)
+
+# if a server fails then it will choose another server randomly from the list and continue.
+
+trap 'echo error' ERR
+
+ips=(64.90.182.55 96.47.67.105 206.246.122.250 64.236.96.53 216.119.63.113 64.250.177.145 208.66.175.36 50.77.217.185 66.219.116.140 216.229.0.179 128.138.140.44 128.138.141.172 198.60.73.8 64.250.229.100 216.228.192.69 207.200.81.113 69.25.96.13 216.171.124.36 64.147.116.229)
+
+r=$RANDOM
+ips_length=`expr ${#ips[@]} - 1`
+
+remote=$1
+new_server=$(( r %= $ips_length ))
+
+URL=${ips[${new_server}]}
+PORT=13
+
+clear_line() {
+ printf '\r'
+ printf "%80s" ""
+ printf '\r'
+}
+
+print_time() {
+ test=`cat $1 | egrep -o "..:..:.."`
+ if [ "${test}" ]; then
+ clear_line
+ echo -ne "Current UTC Time: ${test} on ${URL}\r"
+ else
+ r=$RANDOM
+ new_server=$(( r %= $ips_length ))
+ URL=${ips[${new_server}]}
+ clear_line
+ echo -ne "Current UTC Time: -> ${URL}\r"
+ fi
+}
+
+rerun_time_remote() {
+ while [ 1 == 1 ]
+ do
+ print_time < /dev/tcp/$URL/$PORT
+ if [ $? != 0 ]; then
+ r=$RANDOM
+ new_server=$(( r %= $ips_length ))
+ URL=${ips[${new_server}]}
+ fi
+ sleep 5
+ done
+}
+
+rerun_time_local() {
+ while [ 1 == 1 ]
+ do
+ dateString=`date`
+ clear_line
+ echo -ne "Current Local Time: ${dateString}\r"
+ sleep 1
+ done
+}
+
+if [ "${remote}" ]; then
+ rerun_time_remote
+else
+ rerun_time_local
+fi
View
35 ports.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# This script will run a port check on a specified server
+
+# running it is of the form:
+# ./ports.sh server startPort endPort [logfile]
+
+# arguments in [] are optional
+# default logile is ports.txt
+
+workingDirectory=`pwd`
+startPort=$2
+echo "Starting Port: ${startPort}"
+endPort=`expr $3 + 1`
+echo "Ending Port: ${3}"
+ip=$1
+echo "IP to Check: ${ip}"
+port=$startPort
+file=$4
+if [ "${file}" ]; then
+ folder="${workingDirectory}/${file}"
+else
+ folder="${workingDirectory}/ports.txt"
+fi
+date=`date`
+echo "Logfile: ${folder}"
+echo "" >> $folder
+echo "======================================================" >> $folder
+echo "Log of port check on ${date}" >> $folder
+echo "======================================================" >> $folder
+while [ $port -lt $endPort ]
+do
+ echo &> /dev/null > /dev/tcp/$ip/$port
+ [ $? == 0 ] && echo "Found ${ip}:${port} opened" >> $folder && echo "Found ${ip}:${port} opened"
+ port=`expr $port + 1`
+done
Please sign in to comment.
Something went wrong with that request. Please try again.