Wednesday 7 October 2015

Killing networking Commands with Command Prompt

                   These commands which will be very useful if your machine is connected over a network where hundreds or thousands of machine connected together.

ipconfig 

            This command will get your current ip address configuration with IPv4 address, default gateway and Subnet mask. If you want to get some more advanced information about your network , then go for the same command with /all after command with white space.



                      This will list a bunch of informartion about entire network information like IPv6 Address , DNS configuration , Network Adaptor Details , MAC address etc.,.



                     If you have enabled DHCP in your machine to renew and to get the new IP address type the command followed by ipconfig as ipconfig /renew

hostname

This command will prints the host name of our machine.


getmac

This will print the MAC address of you r machine will be single value if single interface card is present.


ping

If you want to check whether you  are connected to your network use ping command with neighbor host or other machine connected with your network.

                          You can also check with your internet connectivity with command prompt itself by typing any url followed by the ping command. Eg : ping www.google.com



telnet 

This command can be used for getting remote machine information with its server and client. For that we have to enable telnet client or server in our windows machine.

If you want to check any remote machine within your network use the following command
telnet <IPAddress> <Port>

How to enable telnet in Windows 8

      Before going to give details about how to enable telnet client in Windows 8 , better will learn something about telnet and it's uses.

                 Telnet which is available for both Windows and Linux environment . Telnet is basically one of the networking protocol with helps to communicate with a remote machine.

         In windows there are two things as part available such as telnet server and telnet client . Telnet Server enables you to manage a remote machine . In order to display the local server settings with telnet type the command tlntadmn.

Let's get on to the thing of how enable telnet server\client in Windows 8 machine in a simple way.

Go to the search tab my moving pointer to the right corner of your windows machine.

            Type turn windows and this will result option of Turn Windows feature On/Off.
Click on that will show the window like this.





In that you can see both Telnet Client and Server which we can enable and once done click OK . It will take few minutes to and it will be enabled automatically once we finished with the configuration.



To execute telnet commands open command prompt and type with the required telnet command. For example if you want to check a remote machine TCP port is open or already used by some other application . Type the command :

telnet 192.16.0.121 80

In this command telnet command followed by the ip address of the remote machine and the port need to check.


If the specified port is used by another application it will shows with message.

Friday 2 October 2015

Simple Powershell Scripting


               Powershell always rocking with its possibilities. As it mark's it one of the advantage is scripting over powershell .Powershell scripting is nothing like simply batch scripting but with bit advanced and powerful.

               Powershell scripts are nothing but simple text files with .ps1 extension. You can create powershell script in any if things like textpad , notepad or notepad++ etc.,. simply by typing whatever content we need and save it with .ps1 extension.

             Let's start with the simple sample script which is giving addition of two numbers.
The main thing in powershell is declaration and usage of variables. But it's pretty much simple than you thought because there is no data types or limitation of range here.We can store anything in a variable with powershell scripting.

Variable can be defined by using dollar($) symbol before your user defined variable variable name.

Eg:$a = 5 Here $a is the variable which holds the value 5. As I told earlier we can store any type of data in powershell variable . If you want to store your credential in a single variable that's also possible with powershell script.The following is the simple script which will give the addition of 2 numbers.

$a = 10
$b = 34
$c = $a + $b
Write-host "Result is :: "  + $c



Here you can se some command called Write-Host which is nothing but print statement in any of the language like c or c++ or Java

Here this is simple static program. What to do if you want to decide the value at run time ?
Simply it's possible by getting input from the user.

This can be achieved by means of 2 ways either passing as arguments or getting input from user and show it with resultant value.
At first I will explain how to make a script to accept arguments. The script will be

$a = $args[0]
$b = $args[1]
$c = $a + $b
Write-host "Result is :: " $c

pause






Here pause is optional which will be useful when run it using Run command.

Now scripts are ready. Then how to execute the script ?
It's simple with powershell. You can simply drag and drop the script in powershell window or navigate to path where script got located ant type the script name followed by .\ and click Enter to get the result.

If you want to run script without opening console type Powershell.exe and then followed by file location in Windows Run command.

Is it done ? defnintely not. If you execute script in your powershell for the first time it will show error like execution of script is disabled in this system.



Because by default script execution is in restricted state in Windows powershell in any of the system.
In order to enable this in you machine you can use any one of the following execution mode.

You have yo use the command Set-ExecutionPolicy -ExecutionPolicy followed by any one of the following execution mode.

 Unrestricted - No requirements script can be simply executed .
 RemoteSigned - Execute all local script and remote but remote script should be of signed one.
 Allsigned    - Both local and remote script need to be signed.

 For my betterment i will make it as Unrestricteed in my machine by using the command
Set-ExecutionPolicy -ExecutionPolicy Unrestricted



If you execute this command it will whether to allow it or not type 'Y' and fire enter.
If I am enabling in my system fir the first time i got some error likr this. So to solve that again launch powershell as administrator.





That's it with the basic scripting behind powershell since it is such a simple initiative to your advanced scripting.