command_dev_query_raw.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #!/bin/bash
  2. # LinuxGSM command_dev_query_raw.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Raw gamedig output of the server.
  7. commandname="DEV-QUERY-RAW"
  8. commandaction="Developer query raw"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. check.sh
  12. info_game.sh
  13. info_distro.sh
  14. info_messages.sh
  15. echo -e ""
  16. echo -e "${lightgreen}Query IP Addresses${default}"
  17. echo -e "=================================================================="
  18. echo -e ""
  19. for queryip in "${queryips[@]}"; do
  20. echo -e "${queryip}"
  21. done
  22. echo -e ""
  23. echo -e "${lightgreen}Game Server Ports${default}"
  24. echo -e "=================================================================="
  25. {
  26. echo -e "${lightblue}Port Name \tPort Number \tStatus \tTCP \tUDP${default}"
  27. if [ -v port ]; then
  28. echo -e "Game: \t${port} \t$(ss -tupl | grep -c "${port}") \t$(ss -tupl | grep "${port}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${port}" | grep udp | awk '{ print $2 }')"
  29. else
  30. echo -e "Game:"
  31. fi
  32. if [ "${shortname}" == "rw" ]; then
  33. if [ -v port2 ]; then
  34. echo -e "Game+1: \t${port2} \t$(ss -tupl | grep -c "${port}") \t$(ss -tupl | grep "${port2}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${port2}" | grep udp | awk '{ print $2 }')"
  35. else
  36. echo -e "Game+1:"
  37. fi
  38. if [ -v port3 ]; then
  39. echo -e "Game+2: \t${port3} \t$(ss -tupl | grep -c "${port}") \t$(ss -tupl | grep "${port3}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${port3}" | grep udp | awk '{ print $2 }')"
  40. else
  41. echo -e "Game+2:"
  42. fi
  43. if [ -v port4 ]; then
  44. echo -e "Game+3: \t${port4} \t$(ss -tupl | grep -c "${port}") \t$(ss -tupl | grep "${port4}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${port4}" | grep udp | awk '{ print $2 }')"
  45. else
  46. echo -e "Game+3:"
  47. fi
  48. fi
  49. if [ "${shortname}" == "pvr" ]; then
  50. if [ -v port401 ]; then
  51. echo -e "Game+400: \t${port401} \t$(ss -tupl | grep -c "${port401}") \t$(ss -tupl | grep "${port401}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${port401}" | grep udp | awk '{ print $2 }')"
  52. else
  53. echo -e "Game+400:"
  54. fi
  55. fi
  56. if [ "${shortname}" == "mcb" ]; then
  57. if [ -v portipv6 ]; then
  58. echo -e "Game ipv6: \t${portipv6} \t$(ss -tupl | grep -c "${portipv6}") \t$(ss -tupl | grep "${portipv6}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${portipv6}" | grep udp | awk '{ print $2 }')"
  59. else
  60. echo -e "Game ipv6:"
  61. fi
  62. fi
  63. if [ -v queryport ]; then
  64. echo -e "Query: \t${queryport} \t$(ss -tupl | grep -c "${queryport}") \t$(ss -tupl | grep "${queryport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${queryport}" | grep udp | awk '{ print $2 }')"
  65. else
  66. echo -e "Query:"
  67. fi
  68. if [ -v apiport ]; then
  69. echo -e "Game: \t${apiport} \t$(ss -tupl | grep -c "${apiport}") \t$(ss -tupl | grep "${apiport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${apiport}" | grep udp | awk '{ print $2 }')"
  70. else
  71. echo -e "API:"
  72. fi
  73. if [ -v appport ]; then
  74. echo -e "App: \t${appport} \t$(ss -tupl | grep -c "${appport}") \t$(ss -tupl | grep "${appport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${appport}" | grep udp | awk '{ print $2 }')"
  75. else
  76. echo -e "App:"
  77. fi
  78. if [ -v battleeyeport ]; then
  79. echo -e "BattleEye: \t${battleeyeport} \t$(ss -tupl | grep -c "${battleeyeport}") \t$(ss -tupl | grep "${battleeyeport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${battleeyeport}" | grep udp | awk '{ print $2 }')"
  80. else
  81. echo -e "BattleEye:"
  82. fi
  83. if [ -v beaconport ]; then
  84. echo -e "Beacon: \t${beaconport} \t$(ss -tupl | grep -c "${beaconport}") \t$(ss -tupl | grep "${beaconport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${beaconport}" | grep udp | awk '{ print $2 }')"
  85. else
  86. echo -e "Beacon:"
  87. fi
  88. if [ -v clientport ]; then
  89. echo -e "Client: \t${clientport} \t$(ss -tupl | grep -c "${clientport}") \t$(ss -tupl | grep "${clientport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${clientport}" | grep udp | awk '{ print $2 }')"
  90. else
  91. echo -e "Client:"
  92. fi
  93. if [ -v fileport ]; then
  94. echo -e "File: \t${fileport} \t$(ss -tupl | grep -c "${fileport}") \t$(ss -tupl | grep "${fileport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${fileport}" | grep udp | awk '{ print $2 }')"
  95. else
  96. echo -e "File:"
  97. fi
  98. if [ -v httpport ]; then
  99. echo -e "HTTP: \t${httpport} \t$(ss -tupl | grep -c "${httpport}") \t$(ss -tupl | grep "${httpport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${httpport}" | grep udp | awk '{ print $2 }')"
  100. else
  101. echo -e "HTTP:"
  102. fi
  103. if [ -v httpqueryport ]; then
  104. echo -e "HTTP Query: \t${httpqueryport} \t$(ss -tupl | grep -c "${httpqueryport}") \t$(ss -tupl | grep" ${httpqueryport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${httpqueryport}" | grep udp | awk '{ print $2 }')"
  105. else
  106. echo -e "HTTP Query:"
  107. fi
  108. if [ -v httpport ]; then
  109. echo -e "Web Interface: \t${httpport} \t$(ss -tupl | grep -c "${httpport}") \t$(ss -tupl | grep "${httpport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${httpport}" | grep udp | awk '{ print $2 }')"
  110. else
  111. echo -e "Web Interface:"
  112. fi
  113. if [ -v masterport ]; then
  114. echo -e "Game: Master: \t${masterport} \t$(ss -tupl | grep -c "${masterport}") \t$(ss -tupl | grep "${masterport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${masterport}" | grep udp | awk '{ print $2 }')"
  115. else
  116. echo -e "Game: Master:"
  117. fi
  118. if [ -v rawport ]; then
  119. echo -e "RAW UDP Socket: \t${rawport} \t$(ss -tupl | grep -c "${rawport}") \t$(ss -tupl | grep "${rawport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${rawport}" | grep udp | awk '{ print $2 }')"
  120. else
  121. echo -e "RAW UDP Socket:"
  122. fi
  123. if [ -v rconport ]; then
  124. echo -e "RCON: \t${rconport} \t$(ss -tupl | grep -c "${rconport}") \t$(ss -tupl | grep "${rconport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${rconport}" | grep udp | awk '{ print $2 }')"
  125. else
  126. echo -e "RCON:"
  127. fi
  128. if [ -v steamport ]; then
  129. echo -e "Steam: \t${steamport} \t$(ss -tupl | grep -c "${steamport}") \t$(ss -tupl | grep "${steamport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${steamport}" | grep udp | awk '{ print $2 }')"
  130. else
  131. echo -e "Steam:"
  132. fi
  133. if [ -v steamworksport ]; then
  134. echo -e "Steamworks P2P: \t${steamworksport} \t$(ss -tupl | grep -c "${steamworksport}") \t$(ss -tupl | grep "${steamworksport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${steamworksport}" | grep udp | awk '{ print $2 }')"
  135. else
  136. echo -e "Steamworks P2P:"
  137. fi
  138. if [ -v steamauthport ]; then
  139. echo -e "Steam: Auth: \t${steamauthport} \t$(ss -tupl | grep -c "${steamauthport}") \t$(ss -tupl | grep "${steamauthport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${steamauthport}" | grep udp | awk '{ print $2 }')"
  140. else
  141. echo -e "Steam: Auth:"
  142. fi
  143. if [ -v telnetport ]; then
  144. echo -e "Telnet: \t${telnetport} \t$(ss -tupl | grep -c "${telnetport}") \t$(ss -tupl | grep "${telnetport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${telnetport}" | grep udp | awk '{ print $2 }')"
  145. else
  146. echo -e "Telnet:"
  147. fi
  148. if [ -v statsport ]; then
  149. echo -e "Stats: \t${battleeyeport} \t$(ss -tupl | grep -c "${statsport}") \t$(ss -tupl | grep "${statsport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${statsport}" | grep udp | awk '{ print $2 }')"
  150. else
  151. echo -e "Stats:"
  152. fi
  153. if [ -v sourcetvport ]; then
  154. echo -e "SourceTV: \t${sourcetvport} \t$(ss -tupl | grep -c "${sourcetvport}") \t$(ss -tupl | grep "${sourcetvport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${sourcetvport}" | grep udp | awk '{ print $2 }')"
  155. else
  156. echo -e "SourceTV:"
  157. fi
  158. if [ -v udplinkport ]; then
  159. echo -e "UDP Link: \t${udplinkport} \t$(ss -tupl | grep -c "${udplinkport}") \t$(ss -tupl | grep "${udplinkport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${udplinkport}" | grep udp | awk '{ print $2 }')"
  160. else
  161. echo -e "UDP Link:"
  162. fi
  163. if [ -v voiceport ]; then
  164. echo -e "Voice: \t${voiceport} \t$(ss -tupl | grep -c "${voiceport}") \t$(ss -tupl | grep "${voiceport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${voiceport}" | grep udp | awk '{ print $2 }')"
  165. else
  166. echo -e "Voice:"
  167. fi
  168. if [ -v voiceunusedport ]; then
  169. echo -e "Voice (Unused): \t${voiceunusedport} \t$(ss -tupl | grep -c "${voiceunusedport}") \t$(ss -tupl | grep "${voiceunusedport}" | grep tcp | awk '{ print $2 }') \t$(ss -tupl | grep "${voiceunusedport}" | grep udp | awk '{ print $2 }')"
  170. else
  171. echo -e "Voice (Unused):"
  172. fi
  173. } \
  174. | column -s $'\t' -t
  175. echo -e ""
  176. echo -e "${lightgreen}SS Output${default}"
  177. echo -e "================================="
  178. fn_info_message_ports
  179. eval "${portcommand}"
  180. echo -e ""
  181. echo -e "${lightgreen}Query Port - Raw Output${default}"
  182. echo -e "=================================================================="
  183. echo -e ""
  184. echo -e "PORT: ${port}"
  185. echo -e "QUERY PORT: ${queryport}"
  186. echo -e ""
  187. echo -e "${lightgreen}Gamedig Raw Output${default}"
  188. echo -e "================================="
  189. echo -e ""
  190. if [ ! "$(command -v gamedig 2> /dev/null)" ]; then
  191. fn_print_failure_nl "gamedig not installed"
  192. fi
  193. if [ ! "$(command -v jq 2> /dev/null)" ]; then
  194. fn_print_failure_nl "jq not installed"
  195. fi
  196. for queryip in "${queryips[@]}"; do
  197. query_gamedig.sh
  198. echo -e "${gamedigcmd}"
  199. echo""
  200. echo "${gamedigraw}" | jq
  201. done
  202. echo -e ""
  203. echo -e "${lightgreen}gsquery Raw Output${default}"
  204. echo -e "================================="
  205. echo -e ""
  206. for queryip in "${queryips[@]}"; do
  207. echo -e "./query_gsquery.py -a \"${queryip}\" -p \"${queryport}\" -e \"${querytype}\""
  208. echo -e ""
  209. if [ ! -f "${modulesdir}/query_gsquery.py" ]; then
  210. fn_fetch_file_github "lgsm/modules" "query_gsquery.py" "${modulesdir}" "chmodx" "norun" "noforce" "nohash"
  211. fi
  212. "${modulesdir}"/query_gsquery.py -a "${queryip}" -p "${queryport}" -e "${querytype}"
  213. done
  214. echo -e ""
  215. echo -e "${lightgreen}TCP Raw Output${default}"
  216. echo -e "================================="
  217. echo -e ""
  218. for queryip in "${queryips[@]}"; do
  219. echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}''"
  220. echo -e ""
  221. timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}''
  222. querystatus="$?"
  223. echo -e ""
  224. if [ "${querystatus}" == "0" ]; then
  225. echo -e "TCP query PASS"
  226. else
  227. echo -e "TCP query FAIL"
  228. fi
  229. done
  230. echo -e ""
  231. echo -e "${lightgreen}Game Port - Raw Output${default}"
  232. echo -e "=================================================================="
  233. echo -e ""
  234. echo -e "${lightgreen}TCP Raw Output${default}"
  235. echo -e "================================="
  236. echo -e ""
  237. for queryip in "${queryips[@]}"; do
  238. echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}''"
  239. echo -e ""
  240. timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}''
  241. querystatus="$?"
  242. echo -e ""
  243. if [ "${querystatus}" == "0" ]; then
  244. echo -e "TCP query PASS"
  245. else
  246. echo -e "TCP query FAIL"
  247. fi
  248. done
  249. echo -e ""
  250. echo -e "${lightgreen}Steam Master Server Response${default}"
  251. echo -e "=================================================================="
  252. echo -e ""
  253. echo -e "Response: ${displaymasterserver}"
  254. echo -e ""
  255. exitcode=0
  256. core_exit.sh