Advertisement
brianMc

getIP

Sep 23rd, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Queries http://checkip.dyndns.com/
  4. #Displays current ip assigned by ISP
  5. #Appends text file in home directory
  6. #Includes time/date stamp
  7.  
  8. clear
  9. echo "getIP is attempting to get ip..."
  10.  
  11. curl -s http://checkip.dyndns.com/ > /home/$USER/.checkIp
  12.  
  13. sed -n '/<body>Current IP Address:/,/<\/body>/p' /home/$USER/.checkIp | sed -e '1s/.*<body>Current IP Address://' -e '$s/<\/body>.*//' >> /home/$USER/.ip
  14.  
  15. if [ -s /home/$USER/.ip ] ; then
  16.     clear
  17.     echo "Success!"
  18.     ipAd=$(</home/$USER/.ip)
  19.     dateStmp=$(date +%D)
  20.     timeStmp=$(date +%r)
  21.     echo -e "$ipAd - $timeStmp $dateStmp" >> /home/$USER/ISP-ips
  22.     echo -e "Current IP assigned by ISP:$ipAd\n"
  23. else
  24.     clear
  25.     echo -e "No response from CheckIP, try again...\n"
  26. fi
  27.  
  28. rm /home/$USER/.checkIp
  29. rm /home/$USER/.ip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement