Advertisement
NaterTater

NaterTater TMobile Sagemcom Settings Script

Oct 8th, 2022 (edited)
10,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. $ErrorActionPreference = 'SilentlyContinue'
  2. function token
  3. {
  4.  
  5. $Pass = Read-Host "Enter Password For The Gateway"
  6. $body = @"
  7. {
  8. "username": "admin",
  9. "password": "$Pass"
  10. }
  11. "@
  12. $login = Invoke-RestMethod -Method POST -Uri "http://192.168.12.1/TMI/v1/auth/login" -Body $body
  13. $token = $login.auth.token
  14. $global:header = @{Authorization="Bearer $token"}
  15.  
  16. }
  17.  
  18. function Show-Menu
  19. {
  20. param (
  21. [string]$Title = 'My Menu'
  22. )
  23. Clear-Host
  24. Write-Host "Options for Gateway"
  25.  
  26. Write-Host "1: Press '1' to Turn Off 2.4G Wifi."
  27. Write-Host "2: Press '2' to Turn On 2.4G Wifi."
  28. Write-Host "3: Press '3' to Turn Off 5G Wifi."
  29. Write-Host "4: Press '4' to Turn On 5G Wifi."
  30. Write-Host "5: Press '5' to Reboot Gateway."
  31. Write-Host "6: Press '6' to Download Config to Verify Changes."
  32. Write-Host "Q: Press 'Q' to Quit."
  33. }
  34.  
  35.  
  36. function wifi-off-24
  37. {
  38.  
  39. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
  40. ((Get-Content -path .\config.txt -Raw) -Replace '"2.4ghz":{"isRadioEnabled":true','"2.4ghz":{"isRadioEnabled":false') | Set-Content -Path .\config.txt
  41. $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
  42.  
  43. }
  44.  
  45.  
  46. function wifi-on-24
  47. {
  48.  
  49. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
  50. ((Get-Content -path .\config.txt -Raw) -Replace '"2.4ghz":{"isRadioEnabled":false','"2.4ghz":{"isRadioEnabled":true') | Set-Content -Path .\config.txt
  51. $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
  52.  
  53. }
  54. function wifi-off-5
  55. {
  56.  
  57. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
  58. ((Get-Content -path .\config.txt -Raw) -Replace '"5.0ghz":{"isRadioEnabled":true','"5.0ghz":{"isRadioEnabled":false') | Set-Content -Path .\config.txt
  59. $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
  60.  
  61. }
  62.  
  63.  
  64. function wifi-on-5
  65. {
  66.  
  67. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
  68. ((Get-Content -path .\config.txt -Raw) -Replace '"5.0ghz":{"isRadioEnabled":false','"5.0ghz":{"isRadioEnabled":true') | Set-Content -Path .\config.txt
  69. $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/network/configuration?set=ap" -headers $global:header -body (Get-Content .\config.txt) -ContentType "application/json"
  70.  
  71. }
  72.  
  73.  
  74. function config
  75. {
  76.  
  77. $response = Invoke-RestMethod -Uri "http://192.168.12.1/TMI/v1/network/configuration?get=ap" -headers $global:header -o .\config.txt
  78.  
  79. }
  80.  
  81. function reboot
  82. {
  83.  
  84. $response = Invoke-RestMethod -TimeoutSec 1 -Method POST -Uri "http://192.168.12.1/TMI/v1/gateway/reset?set=reboot" -headers $global:header
  85.  
  86. }
  87.  
  88.  
  89.  
  90. function menu
  91. {
  92.  
  93.  
  94. Show-Menu -Title 'My Menu'
  95. $selection = Read-Host "Please make a selection"
  96. switch ($selection)
  97. {
  98. '1' {
  99.  
  100. 'Turning off 2.4G Wifi'
  101. wifi-off-24
  102. 'Returning to Menu'
  103. Start-Sleep -s 1
  104. menu
  105.  
  106. } '2' {
  107.  
  108. 'Turning on 2.4G Wifi'
  109. wifi-on-24
  110. 'Returning to Menu'
  111. Start-Sleep -s 1
  112. menu
  113.  
  114.  
  115. }'3' {
  116.  
  117. 'Turning off 5G Wifi'
  118. wifi-off-5
  119. 'Returning to Menu'
  120. Start-Sleep -s 1
  121. menu
  122.  
  123. } '4' {
  124.  
  125. 'Turning on 5G Wifi'
  126. wifi-on-5
  127. 'Returning to Menu'
  128. Start-Sleep -s 1
  129. menu
  130. } '5' {
  131.  
  132. 'Rebooting Gateway'
  133. Start-Sleep -s 1
  134.  
  135. reboot
  136. return
  137.  
  138. } '6' {
  139. 'Downloading config'
  140. config
  141. 'Returning to Menu'
  142. Start-Sleep -s 1
  143. menu
  144.  
  145.  
  146. } 'q' {
  147. return
  148. }
  149. }
  150.  
  151. }
  152. token
  153. menu
  154.  
  155. $response
  156.  
  157.  
  158.  
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement