Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # @(#) generate-rfc4193-addr.sh (ULA) (c) Sep 2004 - Jun 2011 Holger Zuleger
  4. #
  5. # do what the name suggest
  6. #
  7. # firstpart = 64-Bit NTP time
  8. # secondpart = EUI-64 Identifier or 48 Bit MAC-Adress
  9. # sha1sum ($firstpart | $secondpart )
  10. # use least significant 40 Bits of sha1sum
  11. # build global prefix (locally assigned == FD00::/8)
  12. #
  13. # (M1) 11. May 2006
  14. # - a check added to complain if firstpart or secondpart is empty
  15. # - firstpart calculation changed in such a way, that only one transmit
  16. # time is stored (ntpdate since version 4.2.0 use a list of ntp servers)
  17. #
  18. # (M2) 27. Aug 2006
  19. # Fixed bug in using reference time instead of transmit timestamp.
  20. # Thanks to Marc A. Donges for finding this out
  21. #
  22. # (M3) 4. Sep 2006
  23. # Use ntpq instead of ntpdate because the latter is deprecated.
  24. # This requires a local running and syncronized ntpd, but
  25. # speeds up the execution time
  26. #
  27. # (M4) 29. Dec 2006
  28. # set LC_ALL=C at the beginning of the script, to be sure the grep command
  29. # used to scan the output of the ifconfig command finds the expected string
  30. # Thanks to Ted Percival for finding this out
  31. #
  32. # (M5) 5. Jun 2011
  33. # tr command added to remove the trailing newline from the sha1 calculation
  34. # Thanks to Reinard Max for the fix
  35. #
  36. # (M6) 26. Aug 2011
  37. # Modified to work on BSD as well as Linux, and take the interface as $1
  38. #
  39. PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/sbin
  40.  
  41. debug=0
  42. USE_NTPQ=1
  43. NTPSERVER=pool.ntp.org
  44.  
  45. test -z $1 && echo "Usage: $0 INTERFACE" && exit 1
  46.  
  47. #(M4)
  48. LC_ALL=C
  49. export LC_ALL
  50.  
  51. #(M3)
  52. if test $USE_NTPQ -eq 1
  53. then
  54. if time=`ntpq -c rv | grep clock=`
  55. then
  56. test $debug -eq 1 && echo "$time"
  57. firstpart=`echo $time | sed -e "s/clock=//" -e "s/ .*//" -e "s/\.//"`
  58. else
  59. echo "no local ntpd running" 1>&2
  60. exit 1
  61. fi
  62. else
  63. #(M1)
  64. #(M2)
  65. firstpart=`ntpdate -d -q $NTPSERVER 2>/dev/null | sed "/transmit timestamp/q" |
  66. sed -n "/transmit time/s/^transmit timestamp: *\([^ ]*\) .*/\1/p" |
  67. tr -d "."`
  68. fi
  69.  
  70. secondpart=`ifconfig $1 |
  71. egrep "inet6 (addr: )?fe80" |
  72. sed -n "s/^.*fe80::\([0-9a-f\:]*\).*/\1/p" |
  73. tr -d ":"`
  74.  
  75. #(M1)
  76. if test -z "$firstpart" -o -z "$secondpart"
  77. then
  78. echo "$0: installation error: check if ntpdate and ifconfig is in search path"
  79. exit 1
  80. fi
  81.  
  82. test $debug -eq 1 && echo "Firstpart: $firstpart"
  83. test $debug -eq 1 && echo "Secondpart: $secondpart"
  84. test $debug -eq 1 && echo "123456789o123456789o123456789o123456789o123456789o123456789o"
  85. test $debug -eq 1 && echo ${firstpart}${secondpart} | sha1sum
  86.  
  87. #(M5)
  88. globalid=`echo ${firstpart}${secondpart} | tr -d "\012" | sha1sum | cut -c31-40`
  89. test $debug -eq 1 && echo $globalid
  90.  
  91.  
  92. echo fd${globalid} | sed "s|\(....\)\(....\)\(....\)|\1:\2:\3::/48|"
Add Comment
Please, Sign In to add comment