domain name to IP address


/ Published in: Bash
Save to your folder(s)

uses nslookup to find the IP of the domain


Copy this code and paste it in your HTML
  1. #!/bin/sh
  2.  
  3. # Usage: domain2ip domain.name1 ... domain.nameN
  4.  
  5. if test $# -eq 0
  6. then
  7. echo "------------------"
  8. echo "please add domain name to look up ex) domain2ip google.com foo.bar ..."
  9. echo "------------------"
  10. exit 1
  11. fi
  12. echo "------------------"
  13. for names in $@
  14. do
  15. command=`nslookup $1 > d2ip.temp`
  16. command=`grep NXDOMAIN d2ip.temp`
  17. if test $? -eq 0
  18. then
  19. echo "$1 is not a valid IP address"
  20. echo "------------------"
  21. command=`rm -f d2ip.temp`
  22. shift
  23. elif test $? -eq 1
  24. then
  25. ipname=`cat d2ip.temp | grep -i name`
  26. ipadd=`cut -f5 d2ip.temp | grep -i address`
  27. echo "$ipname"
  28. echo "$ipadd"
  29. echo "------------------"
  30. command=`rm -f d2ip.temp`
  31. shift
  32. else
  33. echo "script exited for another reason! :-("
  34. fi
  35. done
  36. exit 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.