look_dns 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. #set -x
  3. clear
  4. ###
  5. #
  6. # Author: Stéphane HUC
  7. # mail: devs@stephane-huc.net
  8. #
  9. # License: BSD Simplified
  10. #
  11. # Github: https://git.framasoft.org/hucste/tools
  12. #
  13. # Date: 2016/03/11
  14. #
  15. ###
  16. ###
  17. #
  18. # launch-it, manually with an adr_ip as: ./look_dns adr_ip! ;-)
  19. #
  20. ###
  21. ip="$1"
  22. address="" name=""
  23. compare() {
  24. if [ "${ip}" = "${address}" ]; then
  25. printf "[ \\33[1;32m%s\\33[0;39m ] %s \n" "OK" "The name ${name} and the address ${address} match!"
  26. else
  27. printf "[ \\33[1;31m%s\\33[0;39m ] %s \n" "K0" "The name ${name} and the address ${address} dismatch!"
  28. fi
  29. }
  30. forward() {
  31. printf "=> Now, searching FORWARD DNS LOOK! \n"
  32. if [ $(which nslookup) ]; then
  33. nslookup "${name}"
  34. address="$(nslookup "${name}" | awk -F ':' '/Address/ {print $2}' | tail -n 1 | tr -d ' ')"
  35. else
  36. host "${name}"
  37. address="$(host "${name}" | awk '{print $4}')"
  38. fi
  39. }
  40. reverse() {
  41. printf "=> Attempt to REVERSE DNS LOOKUP! \n"
  42. if [ $(which nslookup) ]; then
  43. nslookup "${ip}"
  44. name="$(nslookup "${ip}" | awk -F '=' '/name/ {print $2}' | tr -d ' ')"
  45. else
  46. host "${ip}"
  47. name="$(host "${ip}" | awk '{print $5}')"
  48. fi
  49. }
  50. verify_need_variables() {
  51. if [ -z "$ip" ]; then
  52. printf "[ \\33[1;31m%s\\33[0;39m ] %s $0 adr_ip\n" "ERROR" "Relauch with adr ip:"
  53. exit 1;
  54. fi
  55. }
  56. whois_ip() {
  57. echo "=> Whois or not?"
  58. read reply
  59. case "${reply}" in
  60. o|O|y|O|1) whois ${address} ;;
  61. *) exit ;;
  62. esac
  63. }
  64. verify_need_variables
  65. reverse
  66. if [ -n "${name}" ]; then
  67. printf "[ \\33[1;32m%s\\33[0;39m ] %s \n" "OK" "name: ${name}"
  68. sleep 1
  69. forward
  70. compare
  71. whois_ip
  72. else
  73. printf "[ \\33[1;31m%s\\33[0;39m ] %s \n" "ERROR" "NO name returned!"
  74. exit
  75. fi