ipinfo 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. # AUTHOR: Vovchik
  3. # PURPOSE: GUI to show IP config info
  4. # DATE: 14 May 2009
  5. #120201 BK: internationalized.
  6. #120323 replace 'xmessage' with 'yaf-splash'.
  7. #130216 mavrothal: < > mess up gtkdialog.
  8. #131126 zigbert: gui (gtkdialog) improvements.
  9. export TEXTDOMAIN=ipinfo
  10. export OUTPUT_CHARSET=UTF-8
  11. # --------------
  12. # functions
  13. # --------------
  14. [ -f $HOME/.ipinfo ] && . $HOME/.ipinfo || CB0=true
  15. #---------------
  16. get_ip()
  17. #---------------
  18. {
  19. # external ip
  20. if [ "$CB0" = "true" ];then
  21. var0="`wget -O - -q icanhazip.com`"
  22. else
  23. var0="autocheck disabled"
  24. fi
  25. var0="$(gettext '<b>External IP</b> (via icanhazip.com):') ""<b>$var0</b>"
  26. }
  27. export -f get_ip
  28. #---------------
  29. info_func()
  30. #---------------
  31. {
  32. # external ip info
  33. $DEFAULTBROWSER https://major.io/icanhazip-com-faq/ &
  34. }
  35. export -f info_func
  36. # --------------
  37. get_data()
  38. # --------------
  39. {
  40. nl='
  41. '
  42. # tab 1 - interfaces
  43. var01=`echo $(gettext 'Hostname:') "$HOSTNAME"`
  44. var02="`ifconfig | tr '>' ')' | tr '<' '('`" #130216 mavrothal: < > mess up gtkdialog.
  45. # tab 3 - routing
  46. var03="`route -n | sed -e 's%Kernel IP routing table%%'`"
  47. # tab 2
  48. var04="DNS:"
  49. var05=`cat /etc/resolv.conf`
  50. # tab 4 - collect wireless data
  51. wifi="`iwgetid -a | gawk '{print $1}'`"
  52. # echo "mywifi: ""$wifi"
  53. spaces=" "
  54. if [ -n "$wifi" ]; then
  55. var06=`iwgetid -a 2>&1`
  56. var07=`iwgetid -c 2>&1`
  57. var08=`iwgetid -f 2>&1`
  58. var09=`iwgetid -m 2>&1`
  59. var10=`iwlist encryption 2>&1 | grep -v "no encryption"`
  60. var11=`iwlist rate 2>&1 | grep Current`
  61. # concatenate wireless data for display
  62. var12="$var06""$nl""$var07""$nl""$var08""$nl""$var09""$nl""$var10""$nl""$var11""$nl"
  63. var12="`echo "$var12" | tr '>' ')' | tr '<' '(' | sed '/^$/d'`" #130216 mavrothal: < > mess up gtkdialog.
  64. else
  65. var12="<b>$(gettext 'No wireless extensions detected.')</b>"
  66. fi
  67. # tab 5 - collect connection data
  68. var13="`netstat -tan`"
  69. }
  70. # --------------
  71. show_data()
  72. # --------------
  73. {
  74. echo "$var01"
  75. echo
  76. echo "$var02"
  77. echo
  78. echo "$var03"
  79. echo
  80. echo "$var04"
  81. echo "$var05"
  82. echo
  83. echo "$var12"
  84. echo "$var13"
  85. }
  86. # --------------
  87. make_gui()
  88. # --------------
  89. {
  90. XML0='<vbox scrollable="true" shadow-type="0" border-width="15">
  91. <hbox space-expand="true" space-fill="true">
  92. <checkbox>
  93. <label>'$(gettext 'Query icanhazip.com for your external IP ')'</label>
  94. <variable>CB0</variable>
  95. <default>'$CB0'</default>
  96. </checkbox>
  97. <button tooltip-text="'$(gettext 'Get information about icanhazip.com')'" space-expand="true" space-fill="false">
  98. <input file stock="gtk-info"></input>
  99. <action>info_func</action>
  100. </button>
  101. </hbox>
  102. <hbox>
  103. <text use-markup="true" wrap="false" space-expand="false" space-fill="false">
  104. <label>"<tt>'
  105. XML1='<vbox scrollable="true" shadow-type="0" border-width="15">
  106. <hbox>
  107. <text use-markup="true" wrap="false" space-expand="false" space-fill="false">
  108. <label>"<tt>'
  109. XML2=' </tt>"</label>
  110. </text>
  111. <text space-expand="true" space-fill="true"><label>""</label></text>
  112. </hbox>
  113. <text space-expand="true" space-fill="true"><label>""</label></text>
  114. </vbox>'
  115. export IP_Info='
  116. <window title="IP Info - '$(gettext 'Network information')'" icon-name="gtk-network" default_height="450" default_width="600">
  117. <vbox space-expand="true" space-fill="true">
  118. <notebook labels="'$(gettext 'Interfaces')'|'$(gettext 'DNS')'|'$(gettext 'Routing')'|'$(gettext 'Wireless')'|'$(gettext 'Statistics')'" space-expand="true" space-fill="true">
  119. '$XML0'<b>'${var01}'</b>'${nl}${var0}${nl}${nl}${var02}''$XML2'
  120. '$XML1'<b>'${var04}${nl}'</b>'${nl}${var05}''$XML2'
  121. '$XML1'<b>'$(gettext 'Kernel IP routing table')'</b>'${nl}${var03}${nl}${nl}''$XML2'
  122. '$XML1'<b>'$(gettext 'Wireless configuration:')${nl}'</b>'${nl}${var12}''$XML2'
  123. '$XML1'<b>'$(gettext 'Network statistics:')'</b>'${nl}${nl}${var13}''$XML2'
  124. </notebook>
  125. <hbox space-expand="false" space-fill="false">
  126. <button space-expand="false" space-fill="false">
  127. <label>'$(gettext "Ok")'</label>
  128. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  129. <action>exit:OK</action>
  130. </button>
  131. </hbox>
  132. </vbox>
  133. </window>'
  134. }
  135. #
  136. # --------------
  137. display_gui()
  138. # --------------
  139. {
  140. eval `gtkdialog -p IP_Info`
  141. }
  142. # --------------
  143. # end functions
  144. # --------------
  145. # --------------
  146. # main
  147. # --------------
  148. #xmessage -buttons "" -center -bg orange "$(gettext 'Please wait, probing...')" &
  149. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, probing...')" &
  150. XPID=$!
  151. get_ip
  152. get_data
  153. show_data
  154. make_gui
  155. kill $XPID
  156. display_gui
  157. echo "CB0=$CB0" > $HOME/.ipinfo
  158. exit 0
  159. # --------------
  160. # end main
  161. # --------------