Advertisement
Imthedude025

Block incoming IP's and manage them using CMD (Batch)

Apr 2nd, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. ::Block incoming IP's and manage them using CMD W/H GUI! ::
  3. ::Created by RU$$ [http://russdev.mooo.com/] ::
  4. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  5. @echo off
  6. title Block incoming IP's and manage them using CMD
  7.  
  8. ::Check if CMD is open as admin
  9. NET SESSION >nul 2>&1
  10. IF %ERRORLEVEL% EQU 0 (goto :MENU) ELSE (goto :NOTADMIN)
  11.  
  12. :NOTADMIN
  13. cls
  14. echo ERROR: You need to run as an Administrator!
  15. echo.
  16. pause
  17. exit.
  18.  
  19. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  20. :: Main Menu
  21.  
  22. :MENU
  23. cls
  24.  
  25. ::List
  26. echo Current adress list:
  27. echo =======================================================
  28. netsh advfirewall firewall show rule name=all dir=in | find "IP Block:" | find " "
  29. echo =======================================================
  30. echo.
  31. echo Options:
  32. echo [1] Block an IP.
  33. echo [2] Unblock an IP.
  34. echo [3] Enable/Disable a rule.
  35. echo [4] Evaluate existing adress.
  36. echo [5] Exit.
  37. echo.
  38.  
  39. ::Menu
  40. SET INPUT=
  41. SET /P INPUT= Select an option:
  42.  
  43. IF /I '%INPUT%'=='' GOTO :MENU
  44. IF /I '%INPUT%'=='1' GOTO :BLOCK1
  45. IF /I '%INPUT%'=='2' GOTO :UNADD
  46. IF /I '%INPUT%'=='3' GOTO :ENDI
  47. IF /I '%INPUT%'=='4' GOTO :INFO
  48. IF /I '%INPUT%'=='5' exit
  49.  
  50. goto :MENU
  51.  
  52. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  53. :: Block IP
  54.  
  55. :BLOCK1
  56. cls
  57.  
  58. ::List
  59. echo Welcome to the adress blocking menu:
  60. echo #######################################################
  61. echo Overview:
  62. echo.
  63. echo 1. Select a rule name.
  64. echo 2. Select the remoteip. (IP ADRESS)
  65. echo #######################################################
  66. echo.
  67. echo Options:
  68. echo [1] Go back to menu.
  69. echo.
  70.  
  71. ::Menu
  72. SET NAME=
  73. SET /P NAME= Imput a name for this IP:
  74.  
  75. IF /I '%NAME%'=='' GOTO :BLOCK1
  76. IF /I '%NAME%'=='1' (GOTO :MENU) ELSE (GOTO :BLOCK2)
  77.  
  78. goto :BLOCK1
  79.  
  80. :BLOCK2
  81. cls
  82.  
  83. ::List
  84. echo Welcome to the adress blocking menu:
  85. echo #######################################################
  86. echo Overview:
  87. echo.
  88. echo 1. Select a rule name.
  89. echo 2. Select the remoteip. (IP ADRESS)
  90. echo #######################################################
  91. echo.
  92. echo Options:
  93. echo [1] Change name.
  94. echo.
  95.  
  96. ::Menu
  97. SET ADRESS=
  98. SET /P ADRESS= Imput an adress to block:
  99.  
  100. IF /I '%ADRESS%'=='' GOTO :BLOCK2
  101. IF /I '%ADRESS%'=='1' (GOTO :BLOCK1) ELSE (GOTO :BLOCK3)
  102.  
  103. goto :BLOCK2
  104.  
  105. :BLOCK3
  106. cls
  107.  
  108. ::List
  109. echo Please overview your details:
  110. echo.
  111. echo Name: %NAME%
  112. echo Adress: %ADRESS%
  113. echo -------------------------------------------------------
  114. echo.
  115. echo Options:
  116. echo [1] Change name.
  117. echo [2] Change adress.
  118. echo [3] Cancle operation.
  119. echo.
  120.  
  121. ::Menu
  122. SET INPUT=
  123. SET /P INPUT= Are these credentials correct (Y/N):
  124.  
  125. IF /I '%INPUT%'=='' GOTO :BLOCK3
  126. IF /I '%INPUT%'=='1' GOTO BLOCK1
  127. IF /I '%INPUT%'=='2' GOTO BLOCK 2
  128. IF /I '%INPUT%'=='3' GOTO :CANCLE
  129. IF /I '%INPUT%'=='y' GOTO :ADD
  130. IF /I '%INPUT%'=='Y' GOTO :ADD
  131. IF /I '%INPUT%'=='n' GOTO :BLOCK1
  132. IF /I '%INPUT%'=='N' GOTO :BLOCK1
  133.  
  134. goto :BLOCK3
  135.  
  136. :CANCLE
  137. cls
  138. echo Operation cancled. Returning to menu.
  139. echo.
  140. pause.
  141. GOTO :MENU
  142.  
  143. :ADD
  144. SET COM=IP Block:
  145. SET oNAME=%COM%%NAME%
  146. cls
  147. echo Now creating blocked adress.. Please wait..
  148. echo.
  149. echo ##################
  150. echo Status:
  151. echo ##################
  152. netsh advfirewall firewall add rule name="%oNAME%" dir=in interface=any action=block remoteip=%ADRESS%
  153. echo ##################
  154. echo.
  155. echo Operation complete!
  156. pause.
  157. GOTO :MENU
  158.  
  159. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  160. :: Unblock IP
  161.  
  162. :UNADD
  163. cls
  164.  
  165. ::List
  166. echo Welcome to the blocked adress removal menu:
  167. echo #######################################################
  168. echo Overview:
  169. echo.
  170. echo 1. Select a rule name.
  171. echo 2. Confirm the removal.
  172. echo #######################################################
  173. echo.
  174. echo Current adress list:
  175. echo =======================================================
  176. netsh advfirewall firewall show rule name=all dir=in | find "IP Block:" | find " "
  177. echo =======================================================
  178. echo.
  179. echo Options:
  180. echo [1] Go back to menu.
  181. echo.
  182.  
  183.  
  184. ::Menu
  185. SET NAME=
  186. SET /P NAME= Select an adress name to unblock:
  187.  
  188. IF /I '%NAME%'=='' GOTO :UNADD
  189. IF /I '%NAME%'=='1' (GOTO :MENU) ELSE (GOTO :DELCONFIRM)
  190.  
  191. goto :UNADD
  192.  
  193. :DELCONFIRM
  194. cls
  195.  
  196. ::List
  197. echo Welcome to the blocked adress removal menu:
  198. echo #######################################################
  199. echo Overview:
  200. echo.
  201. echo 1. Select a rule name.
  202. echo 2. Confirm the removal.
  203. echo #######################################################
  204. echo.
  205. echo Removing IP:
  206. echo =======================================================
  207. echo IP Adress: %name%
  208. echo =======================================================
  209. echo.
  210. echo Options:
  211. echo [1] Go back to menu.
  212. echo.
  213.  
  214. ::Menu
  215. SET INPUT=
  216. SET /P INPUT= Do you wish to confirm this action? (Y/N):
  217.  
  218. IF /I '%INPUT%'=='' GOTO :DELCONFIRM
  219. IF /I '%INPUT%'=='N' GOTO :UNADD
  220. IF /I '%INPUT%'=='n' GOTO :UNADD
  221. IF /I '%INPUT%'=='Y' GOTO :DELETE
  222. IF /I '%INPUT%'=='y' GOTO :DELETE
  223.  
  224. goto :DELCONFIRM
  225.  
  226. :DELETE
  227. cls.
  228. echo Now removing %NAME%.. Please wait..
  229. echo.
  230. echo ##################
  231. echo Status:
  232. echo ##################
  233. netsh advfirewall firewall delete rule name="IP Block: %NAME%"
  234. echo ##################
  235. echo.
  236. echo Operation complete!
  237. pause.
  238. GOTO :MENU
  239.  
  240. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  241. :: ENDI (Enable/Disable)
  242.  
  243. :ENDI
  244. cls
  245.  
  246. ::List
  247. echo Welcome to the enable/disable rule menu:
  248. echo #######################################################
  249. echo Overview:
  250. echo.
  251. echo 1. Select a rule name.
  252. echo 2. Imput to enable or disable rule.
  253. echo #######################################################
  254. echo.
  255. echo Current adress list:
  256. echo =======================================================
  257. echo ENABLED RULES:
  258. echo.
  259. netsh advfirewall firewall show rule status=enabled name=all dir=in | find "IP Block:" | find " "
  260. echo.
  261. echo DISABLED RULES:
  262. echo.
  263. netsh advfirewall firewall show rule status=disabled name=all dir=in | find "IP Block:" | find " "
  264. echo =======================================================
  265. echo.
  266. echo Options:
  267. echo [1] Go back to menu.
  268. echo.
  269.  
  270. ::Menu
  271. SET NAME=
  272. SET /P NAME= Select a rule to invoke:
  273.  
  274. IF /I '%NAME%'=='' GOTO :ENDI
  275. IF /I '%NAME%'=='1' (GOTO :MENU) ELSE (GOTO :INVOKERULE)
  276.  
  277. goto :ENDI
  278.  
  279. :INVOKERULE
  280. cls
  281.  
  282. ::List
  283. echo Welcome to the enable/disable rule menu:
  284. echo #######################################################
  285. echo Overview:
  286. echo.
  287. echo 1. Select a rule name.
  288. echo 2. Imput to enable or disable rule.
  289. echo #######################################################
  290. echo.
  291. echo Current adress list:
  292. echo =======================================================
  293. echo ENABLED RULES:
  294. echo.
  295. netsh advfirewall firewall show rule status=enabled name=all dir=in | find "IP Block:" | find " "
  296. echo.
  297. echo DISABLED RULES:
  298. echo.
  299. netsh advfirewall firewall show rule status=disabled name=all dir=in | find "IP Block:" | find " "
  300. echo =======================================================
  301. echo.
  302. echo Options:
  303. echo [1] Go back to name.
  304. echo.
  305.  
  306. ::Menu
  307. SET OPTION=
  308. SET /P OPTION= Do you wish to (enable) or (disable) %NAME%:
  309.  
  310. IF /I '%OPTION%'=='' GOTO :INVOKERULE
  311. IF /I '%OPTION%'=='enable' SET OPTION=yes & GOTO :INVOKE
  312. IF /I '%OPTION%'=='Enable' SET OPTION=yes & GOTO :INVOKE
  313. IF /I '%OPTION%'=='disable' SET OPTION=no & GOTO :INVOKE
  314. IF /I '%OPTION%'=='Disable' SET OPTION=no & GOTO :INVOKE
  315. IF /I '%OPTION%'=='1' GOTO :ENDI
  316.  
  317. goto :INVOKERULE
  318.  
  319. :INVOKE
  320. cls.
  321. echo Now changing %NAME%'s Rule.. Please wait..
  322. echo.
  323. echo ##################
  324. echo Status:
  325. echo ##################
  326. netsh advfirewall firewall set rule name="IP Block: %NAME%" new enable=%OPTION%
  327. echo ##################
  328. echo.
  329. echo Operation complete!
  330. pause.
  331. GOTO :MENU
  332.  
  333. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  334. :: INFO
  335.  
  336. :INFO
  337. cls
  338.  
  339. ::List
  340. echo Current adress list:
  341. echo =======================================================
  342. netsh advfirewall firewall show rule name=all dir=in | find "IP Block:" | find " "
  343. echo =======================================================
  344. echo.
  345. echo Options:
  346. echo [1] Go back to menu.
  347. echo.
  348.  
  349.  
  350. ::Menu
  351. SET INPUT=
  352. SET /P INPUT= Select an adress name to view more info:
  353.  
  354. IF /I '%INPUT%'=='' GOTO :INFO
  355. IF /I '%INPUT%'=='1' (GOTO :MENU) ELSE (GOTO :SET)
  356.  
  357. goto :INFO
  358.  
  359. :SET
  360. cls.
  361. echo Viewing info for %INPUT%.
  362. echo.
  363. netsh advfirewall firewall show rule dir=in name="IP Block: %INPUT%"
  364. echo.
  365. pause.
  366. GOTO :MENU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement