Advertisement
EnterpriseScripts

Local Domain Name Setup Creator

Apr 8th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Winbatch 10.14 KB | None | 0 0
  1. @echo off
  2. REM Uploaded with permission by EnterpriseScripts on http://f.akk.li/escripts
  3. REM We are not liable for anything you do with that script or scripts created by that script.
  4. REM Usage:
  5. REM Launch LDNSc.bat (this file) and setup port forwarding and modes.
  6. REM This version also supports Port forwarding.
  7. REM Do not change any of the values below.
  8. REM Comment: I made this for modular Hostname changes on local systems.
  9.  
  10. REM Copyright (c) 2017 404#0404 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. IF YOU USE THE GENERATED MODULE SCRIPT FOR YOUR COMMERCIAL OR FREE PROJECTS, PLEASE COPY AND INCLUDE THAT COPYRIGHT NOTICE IN THEM TOO.
  11.  
  12. title LDNSc (Local domain name setup creator)
  13. set silent=no
  14. set destination=
  15. set destination_port=
  16. set local_domain_name=
  17. set add_www=yes
  18. set needs_portfw=no
  19. set local_ip=
  20. set local_port=
  21. set uid=%random%%random%
  22. set e=echo
  23. set s=set /p c=
  24. set a=Type yes or no.
  25. set b=or type q to return.
  26. set d=About your
  27. :a
  28. cls
  29. %e% Hello %username%!
  30. %e%.
  31. %e% Please configure your setup here and type "done" when you finish!
  32. %e%.
  33. %e% [1] Silent mode [Currently set to: %silent%]
  34. %e% [2] External IP [Currently set to: %destination%]
  35. %e% [3] Provide www. to your ldn [Currently set to: %add_www%]
  36. %e% [4] Local Domain Name [Currently set to: %local_domain_name%]
  37. %e% [5] Custom UID [Currently set to: %uid%]
  38. %e%.
  39. %e% -----Configure this for Port forwarding-----
  40. %e% [6] Local IP [Currently set to: %local_ip%]
  41. %e% [7] Local Port [Currently set to: %local_port%]
  42. %e% [8] External Port [Currently set to: %destination_port%]
  43. %e%.
  44. %e% [9] Exit the setup
  45. %e%.
  46. set /p ch=Num^>
  47. if "%ch%"=="" goto a
  48. if "%ch%"=="1" goto b
  49. if "%ch%"=="2" goto c
  50. if "%ch%"=="3" goto e
  51. if "%ch%"=="4" goto f
  52. if "%ch%"=="5" goto i
  53. if "%ch%"=="6" goto g
  54. if "%ch%"=="7" goto h
  55. if "%ch%"=="8" goto d
  56. if "%ch%"=="9" goto :eof
  57. if "%ch%"=="done" goto j
  58. goto a
  59. :b
  60. %e% About the silent mode:
  61. %e% The silent mode switch allows you to start the final product silently everytime you call it.
  62. %e% You can optionally run a non-silent script silently by using the first
  63. %e% parameter "silent".
  64. %e% It is perfectly to set this option on yes if you want to run this script within another script.
  65. %e%.
  66. %e% %a%
  67. %e% %b%
  68. %e%.
  69. %s%Inp^>
  70. if "%c%"=="" goto b
  71. if "%c%"=="yes" set silent=yes&goto a
  72. if "%c%"=="no" set silent=no&goto a
  73. if "%c%"=="q" goto a
  74. goto a
  75. :c
  76. %e% This is the external IP which will be called when you try to reach your local
  77. %e% domain name.
  78. %e% Please enter the external IP.
  79. %e%.
  80. %e% %b%
  81. %e%.
  82. %s%IP^>
  83. if "%c%"=="" goto c
  84. if "%c%"=="q" goto a
  85. set destination=%c%
  86. goto a
  87. :d
  88. %e% This is the external port of the external IP.
  89. %e%.
  90. %e% Please enter the port of the external IP.
  91. %e%.
  92. %e% or type q to return.
  93. %e%.
  94. %s%Port^>
  95. if "%c%"=="" goto d
  96. if "%c%"=="q" goto a
  97. set destination_port=%c%
  98. set needs_portfw=yes
  99. goto a
  100. :e
  101. %e% About the www. option.
  102. %e% If your ldn is my.local.page this option would also map www.my.local.page
  103. %e%.
  104. %e% This won't affect my.local.page at all.
  105. %e%.
  106. %e% %a%
  107. %e% %b%
  108. %e%.
  109. %s%Inp^>
  110. if "%c%"=="" goto e
  111. if "%c%"=="yes" set add_www=yes&goto a
  112. if "%c%"=="no" set add_www=no&goto a
  113. if "%c%"=="q" goto a
  114. goto e
  115. :f
  116. %e% %d% local domain name (ldm):
  117. %e% This is the name that'll be used to reach your external IP.
  118. %e%.
  119. %e% Type the local domain name %b%
  120. %e%.
  121. %s%Inp^>
  122. if "%c%"=="" goto f
  123. if "%c%"=="q" goto a
  124. set local_domain_name=%c%
  125. goto a
  126. :g
  127. %e% %d% local IP:
  128. %e% To provide a proper local port redirection you'd need to enter an IP that is
  129. %e% locally not used.
  130. %e% This only needs to bet set when a port redirection is planned.
  131. %e% For example: 127.0.0.2 (That IP can be used already.)
  132. %e%.
  133. %e% Define a local IP here %b%
  134. %e%.
  135. %s%Inp^>
  136. if "%c%"=="" goto g
  137. if "%c%"=="q" goto a
  138. set local_ip=%c%
  139. set needs_portfw=yes
  140. goto a
  141. :h
  142. %e% %d% local port:
  143. %e% Your local port provides access to reach your destination.
  144. %e% This only needs to bet set when a port redirection is planned.
  145. %e% I recommend setting this to 80 for web-services.
  146. %e%.
  147. %s%Inp^>
  148. if "%c%"=="" goto h
  149. if "%c%"=="q" goto a
  150. set local_port=%c%
  151. set needs_portfw=yes
  152. goto a
  153. :i
  154. %e% %d% custom unique ID:
  155. %e% This ID must be unique from all the other ldn end product scripts.
  156. %e% This is because the script needs an ID to remove an installation that is
  157. %e% done by it.
  158. %e% If the same ID gets used by another script both scripts can and will remove
  159. %e% each other on removal request.
  160. %e%.
  161. %e% It generates a random ID so it's not necessary to change it here.
  162. %e% %b%
  163. %e%.
  164. %s%ID^>
  165. if "%c%"=="" goto i
  166. if "%c%"=="q" goto a
  167. set uid=%c%
  168. goto a
  169. :j
  170. set iserror=no
  171. if "%destination%"=="" %e% You need to specify a destination IP.
  172. if "%destination%"=="" set iserror=yes
  173. if "%local_domain_name%"=="" %e% You need to specify a local domain name.
  174. if "%local_domain_name%"=="" set iserror=yes
  175. if "%uid%"=="" %e% You need to specify a UID. It won't work without it.
  176. if "%uid%"=="" set iserror=yes
  177. if not "%iserror%"=="yes" goto k
  178. %e% Please press a key to return to the menu.
  179. %e%.
  180. pause >> nul
  181. goto a
  182. :k
  183. %e% Please specify a filename to save the file in the script directory.
  184. %e%.
  185. set /p saveas=Filename^>
  186. %e% @setlocal enableextensions enabledelayedexpansion>%saveas%
  187. %e% @echo off>>%saveas%
  188. %e% REM Developed by: 404#0404 on Discord. (c) 2016 Do not remove this note.>>%saveas%
  189. %e% set ejnkf=%silent%>>%saveas%
  190. %e% set uesrg=%destination%>>%saveas%
  191. %e% set eznbv=%local_domain_name%>>%saveas%
  192. %e% set aiujr=%add_www%>>%saveas%
  193. %e% set ojers=%needs_portfw%>>%saveas%
  194. %e% set suser=%destination_port%>>%saveas%
  195. %e% set jknme=%local_ip%>>%saveas%
  196. %e% set mfioer=%local_port%>>%saveas%
  197. %e% set mklfse=%uid%>>%saveas%
  198. %e% set dmwoa=%%SystemRoot%%\system32\drivers\etc\hosts>>%saveas%
  199. %e% set dalkmi=%%SystemRoot%%\system32\drivers\etc\hosts-temp>>%saveas%
  200. %e% set oaern=%%1>>%saveas%
  201. %e% if "%%ejnkf%%"=="no" title ldn setup>>%saveas%
  202. %e% if "%%1"=="" goto 18559>>%saveas%
  203. %e% if not x%%oaern:silent=%%==x%%oaern%% set ejnkf=yes>>%saveas%
  204. %e% :18559>>%saveas%
  205. %e% set uirgv=%%SystemRoot%%\system32\drivers\etc\isAdmin>>%saveas%
  206. %e% if exist %%uirgv%% rmdir /Q %%uirgv%%>>%saveas%
  207. %e% mkdir %%uirgv%% ^> nul 2^> nul>>%saveas%
  208. %e% if "%%errorlevel%%"=="0" rmdir /Q %%uirgv%%>>%saveas%
  209. %e% if "%%errorlevel%%"=="1" goto mcioew>>%saveas%
  210. %e% findstr /C:"%%mklfse%%" %%dmwoa%% ^>^> nul>>%saveas%
  211. %e% if errorlevel 1 goto zefwi>>%saveas%
  212. %e% goto 17197>>%saveas%
  213. %e% :zefwi>>%saveas%
  214. %e% echo Hello %%username%%>>%saveas%
  215. %e% echo.>>%saveas%
  216. %e% if "%%ejnkf%%"=="no" echo Press a key to install following settings to your computer:>>%saveas%
  217. %e% if "%%ejnkf%%"=="yes" echo The script will now install following settings to your computer:>>%saveas%
  218. %e% echo Forwarding the local domain "%%eznbv%%" to: %%uesrg%%>>%saveas%
  219. %e% if "%%ojers%%"=="no" echo Needs port forwarding: no>>%saveas%
  220. %e% if "%%ojers%%"=="yes" echo Port of the external IP: %%suser%%^&echo Forwarding port locally to: %%jknme%%:%%mfioer%%>>%saveas%
  221. %e% echo.>>%saveas%
  222. %e% if "%%ejnkf%%"=="no" pause ^>^> nul>>%saveas%
  223. %e% goto fmoiesr>>%saveas%
  224. %e% :fmoiesr>>%saveas%
  225. %e% if "%%ojers%%"=="no" echo %%uesrg%% %%eznbv%% #%%mklfse%%^>^>%%dmwoa%%>>%saveas%
  226. %e% if "%%ojers%%"=="no" if "%%aiujr%%"=="yes" echo %%uesrg%% www.%%eznbv%% #%%mklfse%%^>^>%%dmwoa%%>>%saveas%
  227. %e% if "%%ojers%%"=="yes" echo %%jknme%% %%eznbv%% #%%mklfse%%^>^>%%dmwoa%%>>%saveas%
  228. %e% if "%%ojers%%"=="yes" if "%%aiujr%%"=="yes" echo %%jknme%% www.%%eznbv%% #%%mklfse%%^>^>%%dmwoa%%>>%saveas%
  229. %e% if "%%ojers%%"=="yes" netsh interface portproxy add v4tov4 listenaddress=%%jknme%% listenport=%%mfioer%% connectaddress=%%uesrg%% connectport=%%suser%%>>%saveas%
  230. %e% echo Installation done.>>%saveas%
  231. %e% if "%%ojers%%"=="yes" echo You may now access %%uesrg%% through your browser with: %%eznbv%%:%%mfioer%%>>%saveas%
  232. %e% if "%%ojers%%"=="no" echo You may now access %%uesrg%% through your browser with: "%%eznbv%%">>%saveas%
  233. %e% if "%%ejnkf%%"=="no" echo Press a key to exit installation successfully.>>%saveas%
  234. %e% if "%%ejnkf%%"=="yes" echo Installation successfully exiting script..>>%saveas%
  235. %e% if "%%ejnkf%%"=="no" pause ^>^> nul>>%saveas%
  236. %e% goto :eof>>%saveas%
  237. %e% :17197>>%saveas%
  238. %e% if "%%ejnkf%%"=="no" echo An installation was found.^& echo Press a key to undo previous changes done by the script.>>%saveas%
  239. %e% if "%%ejnkf%%"=="no" pause ^>^> nul>>%saveas%
  240. %e% if "%%ejnkf%%"=="yes" echo Removing previous changes done by the script..>>%saveas%
  241. %e% copy %%dmwoa%% %%SystemRoot%%\system32\drivers\etc\hosts-backup ^>^> nul>>%saveas%
  242. %e% findstr -V /C:"%%mklfse%%" %%dmwoa%% ^> %%dalkmi%%>>%saveas%
  243. %e% MOVE /Y %%dalkmi%% %%dmwoa%% ^>^> nul>>%saveas%
  244. %e% if "%%ojers%%"=="yes" netsh interface portproxy delete v4tov4 listenport=%%mfioer%% listenaddress=%%jknme%%>>%saveas%
  245. %e% if "%%ejnkf%%"=="no" echo Removal done. Press a key to exit application.>>%saveas%
  246. %e% if "%%ejnkf%%"=="no" pause ^>^> nul>>%saveas%
  247. %e% if "%%ejnkf%%"=="yes" echo Removal done. Exiting script..>>%saveas%
  248. %e% goto :eof>>%saveas%
  249. %e% :mcioew>>%saveas%
  250. %e% echo This setup needs admin privileges to run.>>%saveas%
  251. %e% echo Please execute this script with a right click and run as Administrator.>>%saveas%
  252. %e% if "%%ejnkf%%"=="no" pause ^>^> nul>>%saveas%
  253. %e% goto :eof>>%saveas%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement