How to configure Windows TCP/IP settings from the Command Prompt (CLI)

Window’s Netsh.exe command-line scripting utility  allows you to display or modify the network configurations of any computer that is currently running a resent flavor of Windows. Netsh.exe also provides a scripting feature that allows you to run a group of commands in batch mode against a computer both locally and remotely.  You can also use Netsh.exe to save a configuration script in a text file for archival purposes or to help you configure

Window’s Netsh.exe command-line scripting utility  allows you to display or modify the network configurations of any computer that is currently running a resent flavor of Windows. Netsh.exe also provides a scripting feature that allows you to run a group of commands in batch mode against a computer both locally and remotely.  You can also use Netsh.exe to save a configuration script in a text file for archival purposes or to help you configure network information when changing networks.

Here are your commands and what they can do.

View your TCP/IP settings.

netsh interface ip show config

 

Configure your computer’s IP address and other TCP/IP related settings.

This command configures the interface named Local Area Connection with the static IP address 192.168.0.101, the subnet mask of 255.255.255.0, and a default gateway of 192.168.0.1:

netsh interface ip set address name="Local Area Connection" static 192.168.0.101 255.255.255.0 192.168.0.1 1

Configure your NIC to automatically obtain an IP address from a DHCP server

netsh interface ip set address "Local Area Connection" dhcp

To configure DNS and WINS addresses from the Command Prompt

netsh interface ip set dns "Local Area Connection" static 192.168.0.101
netsh interface ip set wins "Local Area Connection" static 192.168.0.101

To configure your NIC to dynamically obtain it’s DNS settings

netsh interface ip set dns "Local Area Connection" dhcp

Now let’s say you have a laptop and it travels between 2 separate networks and you need to maintain separate static configurations for each network. There is a simple way to flip back and forth between networks by creating a simple batch file. Here is how it’s done.

First we export your current IP settings to a text file:

netsh -c interface dump > c:\network1.txt

Next we change the settings manually on the interface to the second network and then export it as well:

netsh -c interface dump > c:\network2.txt

Now we have 2 text files, each file represents a network location. Whenever you need to quickly change your IP settings to switch between networks you can run the following commands

netsh -f c:\network1.txt
or
netsh -f c:\network2.txt

Now to make a batch file to execute the command just create a file called network1.bat and network2.bat and add the perspective line to that file. You can also use the global EXEC switch instead of  “-f ”  switch in the batch file with the same results.

Here are all the options available to netsh.exe

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]UserName] [-p Password| *]
    

Commands available:

?              – Displays a list of commands.
add            – Adds a configuration entry to a list of entries.
advfirewall    – Changes to the `netsh advfirewall’ context.
branchcache    – Changes to the `netsh branchcache’ context.
bridge         – Changes to the `netsh bridge’ context.
delete         – Deletes a configuration entry from a list of entries.
dhcp           – Changes to the `netsh dhcp’ context.
dhcpclient     – Changes to the `netsh dhcpclient’ context.
dnsclient      – Changes to the `netsh dnsclient’ context.
dump           – Displays a configuration script.
exec           – Runs a script file.
firewall       – Changes to the `netsh firewall’ context.
help           – Displays a list of commands.
http           – Changes to the `netsh http’ context.
interface      – Changes to the `netsh interface’ context.
ipsec          – Changes to the `netsh ipsec’ context.
lan            – Changes to the `netsh lan’ context.
mbn            – Changes to the `netsh mbn’ context.
namespace      – Changes to the `netsh namespace’ context.
nap            – Changes to the `netsh nap’ context.
netio          – Changes to the `netsh netio’ context.
p2p            – Changes to the `netsh p2p’ context.
ras            – Changes to the `netsh ras’ context.
rpc            – Changes to the `netsh rpc’ context.
set            – Updates configuration settings.
show           – Displays information.
trace          – Changes to the `netsh trace’ context.
wcn            – Changes to the `netsh wcn’ context.
wfp            – Changes to the `netsh wfp’ context.
winhttp        – Changes to the `netsh winhttp’ context.
winsock        – Changes to the `netsh winsock’ context.
wlan           – Changes to the `netsh wlan’ context.

 

Enjoy

Cubert

XYMON External Test Script for APC NetBotz Environment Monitor

So you got a APC environment monitor (NetBotz) and you want XYMON / Hobbit / BB to monitor and alert if your tempature is rising? Funny me too.

I spent several hours trying to get a VB script to built to do this and I am just not a big fan of VB. So being a Perl plucker I desided to write one in Perl and share it with

So you got a APC environment monitor (NetBotz) and you want XYMON / Hobbit / BB to monitor and alert if your tempature is rising? Funny me too.

I spent several hours trying to get a VB script to built to do this and I am just not a big fan of VB. So being a Perl plucker I desided to write one in Perl and share it with everyone.   

Here is what it does:

The script  queries via SNMP the OID for the tempature sensors current state and then create a XYMON file and place it in the tmp folder where XYmon(BBWin) resides  so that the XYMON(BBWin) service can pick it up and transmit the information to the BBDisplay.

Prereqs are: Windows host, BBWin, ActiveState Perl 5 installed on windows, snmpget.exe application located at http://www.snmpsoft.com/freetools/snmpget.html
Place SNMPGET.EXE in an area that is seen by Windows PATH.

Add to BBWin.cfg under the <Externals> area of XML:

<load value=”C:\Perl\bin\perl.exe netbotz.pl” timer=”5m” />

and copy this script to the BBWin/Bin directory. Every 5 minutes you should see a “NetBotz” file created in BBWin/tmp and shortly afterwards BBwin will remove file once data is sent. On your BBDisplay you should get a new column called [NetBotz] and when you select the “Dot” it will display the current temp.

You may need to play with the OID # for your install of Netbotz as mine had 8 ports (OID’s) for tempature monitors but we only used 1 port so I am only monitoring that OID.

OID’s are

1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.1

through

1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.14

So adjust the last digits (1-14) for your sensor location on Netbotz.

Download -> Netbotz Perl script

Enjoy Shannon, aka Cubert

VBScript code: View CPU usage for a process name

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU usage for each process it finds that matches the Process Name provided.

Then I would copy the code below to a .vbs file and run it in a the CLI.


DIM MyPID(20), objProcess, objItems, objitem
DIM XX, I
XX = -1
set objService = getobject("winmgmts:")
for each Process in objService.InstancesOf("Win32_process")
if Process.Name = "svchost.exe" Then XX = XX + 1
if Process.Name = "svchost.exe" Then MyPID(XX) = Process.processid
Next
For I = 0 To 20
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &MyPID(I)& "")
for each objItem in objItems
Wscript.Echo MyPID(I) & " = " & objItem.PercentProcessorTime

Next
Next

APC NetBotz 200 Cacti Temp and Humidity Graphs

How to Graph the APC NetBotz 200 Environment Monitor

Get the data templates ->  cacti-apc-netbotz200-data-templates

Cacti Temp and Humidity Graphs for the APC NETBOTZ 200 is different from the NETBotz 400 and 600 models.

The APC Netbotz200 has 8 sensor inputs on the device so each input has a OID associatedwith it. What I did was scan the MIBs available and found where the Temp and Humidity

How to Graph the APC NetBotz 200 Environment Monitor

Get the data templates ->  cacti-apc-netbotz200-data-templates

Cacti Temp and Humidity Graphs for the APC NETBOTZ 200 is different from the NETBotz 400 and 600 models.

The APC Netbotz200 has 8 sensor inputs on the device so each input has a OID associatedwith it. What I did was scan the MIBs available and found where the Temp and Humidity values were stored. They are not stored in the same OID as the NetBotz 400 and 600 models.

To scan your Netbotz 200:

Sensor #1
(name)
snmpwalk -v1 -c public [IP address of Netbotz] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.3.0.1  
(temp)
snmpwalk -v1 -c public [IP address of Netbotz] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.1
(humidity)
snmpwalk -v1 -c public [IP address of Netbotz] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.6.0.1

Sensor #8 (name)
snmpwalk -v1 -c public [IP Address of Netbotzs] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.3.0.14
(temp)
snmpwalk -v1 -c public [IP address of Netbotz] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.14
(humidity)
snmpwalk -v1 -c public [IP address of Netbotz] 1.3.6.1.4.1.318.1.1.10.4.2.3.1.6.0.14

The last period in the OID starts at 1 and goes to 14. Each one in succession is another sensor on the Netbotz 200. Using snmpwalk to walk the OID’s will show you what is labeled. Walk this OID to see all sensor names (1.3.6.1.4.1.318.1.1.10.4.2.3.1).

In Cacti add a host with the correct IP and SNMP community (Version 1) then apply the templates provided above to pickup sensor #1 If you need more sensors then duplicate the templates and update the OID in them for the next sensor OID #.

Your graphs should look like..

Party on!!

BBWIN VB script for MySQL externals testing

Use BBWin to Monitor Your MySql Server
This little script allows you to quickly test your MySql server using BBWin .

It connects to MySql and queries SHOW STATUS from your server and returns the Stats.

[caption id="attachment_286" align="alignright" width="80" caption="www.AlertOnFailure.com"][/caption]

The script will alert if connection fails or records not returned.

You will need

Use BBWin to Monitor Your MySql Server
This little script allows you to quickly test your MySql server using BBWin .

It connects to MySql and queries SHOW STATUS from your server and returns the Stats.

www.AlertOnFailure.com

The script will alert if connection fails or records not returned.

You will need to install mysql-connector-odbc-5.1.6-win32.msi From [url]dev.mysql.com/downloads/connector/odbc/5.1.html[/url]

You will also need to edit the script and change the server address, database name, user and password.

:arrow: Download file to BBwin\bin folder

MySQL.vbs
Grabs Global stats from MySql server any where on your network
(2.98 KiB) Not downloaded yet
You will need to edit the BBWin\etc\BBWin.cfg file and insert the line below

 


<load value="cscript MySQL.vbs" timer="15m" />

You will not need to reload BBwin. It should pickup the changes to the file and load the test. With in a minute or 2 you should have a new system “Dot” called “MySQL”

PHP preg_match hostname and domain from FQDN

How to get the hostname and the domain name from FQDN in PHP

This sound easy right? So easy that you would think it would be all over the internet as an example on how to parse host names from domain names. Wrong…. I spent a hour one day looking everywhere and all I found was parsing a URL. Well my needs go deeper I need to do a

How to get the hostname and the domain name from FQDN in PHP

This sound easy right? So easy that you would think it would be all over the internet as an example on how to parse host names from domain names. Wrong…. I spent a hour one day looking everywhere and all I found was parsing a URL. Well my needs go deeper I need to do a quick split of host name from domain name not matter how long or nested the domain names were.

There are a bunch of places that give you the same old PHP preg_match examples as found on www.php.net,   “How to parse the domain name from a URL.”

But lets say I want both the host name and the domain name? If you know anything about FQDN then you know that up to the first “.” is host name and everything else is sub domain, domain and root.

Sometimes your going to have a FQDN that = myname.mysub.mysecondsub.mydomain.root

You want to get “myname” & “mysub.mysecondsub.mydomain .root”

So here is how we do it…


//if host needs to be striped from a URL
preg_match('@^(?:http://)?([^/]+)@i', "http://barfly.beaners.bobbers.mybalistics.net/index.html", $matches);
$host = $matches[1];

//else make $host your FQDN and skip the above segment
preg_match("/^(.*?)\.(.*)/", $host, $rest);
echo "My name is" .$rest[1]. "
";
echo "My domain is" .$rest[2]. "
";

I hope this helps someone out there spending hours looking for the right expression.

More VBScript created for BBWin External testing for www.AlertOnFailure.com

AOF adds VBScript created for BBWin External testing to it’s library

[ipconfig]

Microsoft Networking Information Overload
What a name! The MOAB of network information this jewel of a script dumps out all sorts of good information to have at your finger tips.

In this version there is only one status of green so you

AOF adds VBScript created for BBWin External testing to it’s library

[ipconfig]

Microsoft Networking Information Overload
What a name! The MOAB of network information this jewel of a script dumps out all sorts of good information to have at your finger tips.

In this version there is only one status of green so you can’t place a notification on this test but it does provide some really good data to have at your finger tips.

It provides:

All IP, Wins and DNS information
The System name, domain name and current logged in user
All Network Login Profiles
Dump of your routing table
All Network Clients Installed
Host Proxy Server Information
All Network Adapter Configuration Properties

[defrag]

defrag checks each fixed drive on the host and reports back a status of yellow if any drive needs defraging.

Else if all drives report no defrag needed the status is green.

The report shows up as a “System Dot” called “defrag” and you can assign alert notifications to this test. Currently the test only reports a status of yellow or green. there is no red status in this test.

[PWRmgt]

PWRmgt confirms the current power management setting and any power supply alarms and reports the information back to the AOF server.

This does include status changes, Green, Yellow and Red based on the nature of the issues.

This test creates a “System DOT” called “PWRmgt” on the AOF display and can be used to set alert notifications to.

Get Scripts Here

New VBScript created for BBWin External testing for www.AlertOnFailure.com

I’ve created 2 new VB scripts to use with AOF and BBWin’s External test functions. These scripts were tested on BBwin 0.12 and AOF Beta and work great!

[RePing] Ping multiple internal host addresses

Provides the ability to ping multiple host behind a firewall or other device, Great is you need to test to see if a Wireless AP is up or if a network printer is

I’ve created 2 new VB scripts to use with AOF and BBWin’s External test functions. These scripts were tested on BBwin 0.12 and AOF Beta and work great!

[RePing] Ping multiple internal host addresses

Provides the ability to ping multiple host behind a firewall or other device, Great is you need to test to see if a Wireless AP is up or if a network printer is available. There are many systems that do not run a agent that you can ping to see if they are up and running. This all gets reported back to the AOF servers and placed as a “System Dot” called “RePing”. If a host fails to will change status. You can use this to get remote notifications of failures by placing a alert notification rule to the test.

See Script file

[Wares] List All Installed Software on AOF server (BBDisplay)

Wares.vbs is a visual basics script used to upload a list of installed software on a windows host.  In version one we are sending just the data, no status changes are happening. Version 2 will have the ability to alert if apps are added or removed.

See VB Script

These were developed to be used with www.alertonfailures.com  free system monitoring and management services but the scripts will work just fine with any XYmon server or BBDisplay server.

PHP Pagination with timestamp / timeline display

Pagination with a timestamp as the center value

We provide a way to scroll page to page of data and show the time stamp of when the data was collected as part of the page navigations.

Here we setup the first query and findout how many pages we have.

$sql = “SELECT COUNT(*) FROM table where name = ‘” . $name . “‘ and type = ‘”

Pagination with a timestamp as the center value

We provide a way to scroll page to page of data and show the time stamp of when the data was collected as part of the page navigations.

Here we setup the first query and findout how many pages we have.


$sql = "SELECT COUNT(*) FROM table where name = '" . $name . "' and type = '" . $type . "'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 1;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;

Now we need to make the second query for the actual data so we can place our scroll links and then display our data.


$sql = "SELECT * FROM table where name = '" . $name . "' and type = '" . $type . "' ORDER BY data_time DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while($row = mysql_fetch_array($result)){
$data = $row['data'];
$data_time = $row['data_time']; // expected in epoch
}
$range = 8;
echo "Reported data";
if ($currentpage > 1) {
echo " << ";
$prevpage = $currentpage - 1;
echo " < ";
}

for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [";
$rectime = date(DATE_RFC822, $data_time);
echo $rectime;
echo "]
";
} else {
echo " $x ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " > ";
echo " >> ";
}

echo "


";
echo $data;
echo "";

 

You should have a database that use epoch time as its time field then set $data_time to that field. You will get a nice output with links to pages forward and previous and the time stamp in local time in the center as the current page you are on. Great for scrolling throught time dlimited data in a time line.

HOW-to: PHP Multiple Select List Box quick and easy..

Sometimes you find that it requires a little looping to get data from a form when using PHP and Multiple select list boxes. Here is a quick and easy way to loop through select data sent from a form in html. We also show you here how to use a Array of data to create the options. This is great if your doing a database query and need to use

Sometimes you find that it requires a little looping to get data from a form when using PHP and Mulitple select list boxes. Here is a quick and easy way to loop through select data sent from a form in html. We also show you here how to use a Array of data to create the options. This is great if your doing a database query and need to use that data in select box.

HTML :

select id="select[]" multiple="multiple" name="select[]" size="10"

option value=" . $listID . ">" .$listItem. ""; } /option /select

input id="button" name="button" type="submit" value="Submit" /

if (isset($_POST['select'])) {
$az = $_POST['select'];
foreach ($az as $a)
{
echo $a;
}
}