Friday, September 24, 2010

Geo-Location using IP Address


Geo-Location using IP Address
Many web applications use IP address to find the geographical location of the web site visitors. It has uses from catering relevant advertisements to customizing the behavior of web site. Geo-location using IP address is normally done by using databases. There are two different options available: HostIP.info and MaxMind. HostIP.info has exposed its data through a web service. The access to the web service is free; however, the data is not very accurate. MaxMind offers both commercial solutions as well as free solutions. The free solutions also called the lite versions are not highly accurate but the commercial products are extremely accurate. The code presented in this article has been written to work with both MaxMind's database as well as HostIP.info's web service. The default is to use the HostIP.info. You can change the default, by setting NodeInfo.LocationService property.

//Use Maxmind's Getloaction
NodeInfo.LocationService = new Maxmind.NodeInfoLookupService();

//Use HostIP.info's Geolocation
NodeInfo.LocationService = new HostIP.NodeInfoLookupService();
The LocationService property is of the type INodeInfoLocationService which makes it easy to provide custom lookup services. In a later version the class name of the object to create can come from the configuration file. The INodeInfoLocationService is quite simple with just one method named Lookup.

bool Lookup(IPAddress address, NodeInfo nodeInfo);
The Lookup function takes an IP address and populates a NodeInfo object, which stores the latitude, longitude, city, region and the country name.

The HostIP.info web site exposes its API through HTTP GET at the URL: http://api.hostip.info/. For example, you can get the location of the IP address 207.12.0.9 using the following URL:

http://api.hostip.info?ip=207.12.0.9
The response is returned as XML. The XML gives the latitude, longitude, city, state and country. In the parser implemented in this article, the HTTP GET request is issued through the XMLDocument.Load method.

XmlDocument doc = new XmlDocument();
doc.Load(String.Format("http://api.hostip.info/?ip={0}", address));
The individual elements are extracted using XPath queries. For Example, the country name is extracted using the following query.

node = doc.SelectSingleNode("//hostip:countryName", manager);

if (node != null)
{
nodeInfo.Country = node.InnerText;
}
One element of detail to understand here is how namespaces works with XPath. The argument manager, passed to the SelectSingleNode method, is of type XmlNamespaceManager class. The namespace prefixes are indicated using the following code:

XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
manager.AddNamespace("gml", "http://www.opengis.net/gml");
manager.AddNamespace("hostip", "http://www.hostip.info/api");
The latitude, longitude, city and the state are extracted in the similar fashion using XPaths.

The MaxMind lookup service is much simpler. MaxMind provides source code of the library that can read its databases. The code can be downloaded from this URL: http://www.maxmind.com/app/api. The Maxmind.NodeInfoLookupService uses the LookupService class provided by MaxMind. I have only made minor changes to the MaxMind's code and most of the MaxMind's code is retained as it is. Here is the code for the wrapper around MaxMind's code.

LookupService svc = new LookupService(Path.Combine(
Path.GetDirectoryName(
this.GetType().Assembly.Location
),
"GeoLiteCity.dat")
);
Location loc = svc.getLocation(address);

if (loc != null)
{
nodeInfo.Region = loc.region;
nodeInfo.Longitude = loc.longitude;
}
You need to download and extract the GeoCity Lite database from MaxMind.com. The compressed archive of the database is available at the following URL: http://www.maxmind.com/app/geolitecity. The GeoLiteCity.dat must be placed in the same directory as the executable.

This was a brief description of the geo-location code. Now, let's examine how the Virtual Earth API is used in the code.

Using the Virtual Earth API
You can get the same mapping feature in your web applications as local.live.com using the Virtual earth API. The Virtual Earth API is JavaScript code and can be loaded in web pages by including a script:


Once the script is loaded, you can use Javascript classes available in the API. A comprehensive API reference is available at the following URL: http://dev.live.com/virtualearth/sdk/. Also, checkout the interactive SDK tutorial available at the same URL. To display the Virtual Earth map in your web page, you need to designate a
element where you want the map image to appear:


Next you will use some JavaScript to load the map into the designated element:

map = new VEMap("mapContainer");
map.LoadMap();
Notice that so far I have only talked about Virtual earth API as a web based API. Since Tracert Map is a windows application, the question arises: how can we use Virtual Earth in windows application? The answer is simple: host the Internet Explorer in the desktop application. Luckily, the .Net Framework 2.0 provides the WebBrowser control. We need to create an HTML page where we can place all the HTML, JavaScript and CSS and load this page into the hosted web browser. An HTML page named tracert.htm needs to be placed in the directory of the executable, so as to make the following code work:

mapBrowser.Navigate(Path.Combine(Path.
GetDirectoryName(
this.GetType().Assembly.Location
),
"tracert.htm")
);
The code shown till now is sufficient to display the Map, but we need to control the map from C# code. The JavaScript code in the web page also needs to invoke C# code. Luckily, the web browser control has a property called ObjectForScripting for this purpose. This property can be assigned any object, the only catch is that the class needs to be marked with the COMVisible attribute.

[ComVisible(true)] //So that scripts can access the methods
public partial class TracertMapForm : Form
A public method in the class declared as public void MapLoaded() can be accessed from JavaScript using window.external.MapLoaded() statement. This is how JavaScript can use C# code, but how about C# code invoking JavaScript? This can be done by using the InvokeScript function. For Example, the code: mapBrowser.Document.InvokeScript("OnStartTrace"); invokes the JavaScript function OnStartTrace declared as: function OnStartTrace. Now that we know how two way communication between script and C# code can be achieved, let's look at the details of virtual earth API.

We will be using Virtual Earth API to mark nodes on the map. This is called a pushpin in the Virtual Earth terminology. In order to do that we need the latitude and the longitude of the node which was obtained by the geolocation service. To display the pushpin we also need the URL of the image which will be used as pushpin. Images of numbers circled in red can obtained at the following URL: http://local.live.com/i/pins/RedCircleXX.gif, where XX can be replaced by a number. For Example the URL http://local.live.com/i/pins/RedCircle10.gif is the image representation of number 10 enclosed in a RedCircle. To represent the nth node as a pushpin in the map, we use the URL: http://local.live.com/i/pins/RedCircle{n}.gif where {n} is replaced by the actual number. Another, interesting feature of a pushpin is that when the mouse hovers over the pushpin it shows a popup as shown in the screenshot below.


The IP address is displayed in the bold text as the title of the popup and the DNS name in lighter text as the body of the popup. Virtual Earth API takes care of displaying the popup. All we need to do is to specify the popup title and the body when creating the pushpin:

var location = new VELatLong(nodeInfo.Latitude, nodeInfo.Longitude);
var imageURL = "http://local.live.com/i/pins/RedCircle" + hopNo + ".gif";
var pushpin = new VEPushpin(hopNo,
location, //pushpin latitude and longitude
imageURL, //pushpin image
nodeInfo.Address, //Pushpin title
nodeInfo.HostName //Pushpin body
);
map.AddPushpin(pushpin);
The final aspect of the Virtual Earth API which is used in the tool is that of polylines. As seen in the first screenshot the nodes on the map are connected through a blue line. This can be created by using VEPolyline JavaScript object. The code to create a transparent blue polyline through an array of latitude and longitude pairs, named nodes, is shown below:

var poly = new VEPolyline("route", nodes);
poly.SetWidth(2);
poly.SetColor(new VEColor(0, 0, 255, 0.5));
map.AddPolyline(poly);
Final Words
I have described briefly how the tool works and its various elements. The tool is still under development and there are lots of features that need to be added. Please note that the pushpins may not represent the locations accurately. This is because the HostIP.info as well as MaxMind lite databases are not highly accurate. The HostIP.info site allows you to correct its database and I recommend you to correct the database and further improve the excellent and free GeoIP database.


Wednesday, September 15, 2010

Scary Unmanned Aerial Vehicles Used by the Military


Scary Unmanned Aerial Vehicles Used by the Military



The X-47B is designed to be launched either from land or catapult-launched from ships, and could be refueled in midair.

Look out, everybody, because here come the unmanned aerial vehicles, otherwise known as UAVs or drones. They’ve been flourishing in the Iraq War, starting with just a few unarmed drones when the conflict began in 2003, and now growing in numbers to more than 7,000. Many are packing serious missiles and bombs, and some soon could be autonomous. This is undoubtedly the dawn of an entirely new era of military might: robot wars. (Pics)

Flying over battlefields in a variety of shapes and sizes, the aircraft are controlled from either the battlefield itself, thousands of miles away, or anywhere in between. They can keep an eye on bad guys wherever they may roam, and some can even blow them up at a moment’s notice. One reason they’re so compelling for military types: They present no danger to their pilots. To help you recognize and identify these scary robotic birds, we picked out a representative sample of six of these these soulless, empty flyers for you to contemplate.


Micro Air Vehicle


Honeywell’s insect-like micro air vehicles, affectionately known by soldiers as a “flying beer keg,” are used for surveillance. The 13-inch hovering devices are small enough to carry in a backpack, yet large enough to carry a camera that’s just right for finding improvised explosive devices. The first generation is too noisy, though, and not reliable enough, so Honeywell is preparing a second generation model that should be ready for the battlefield by next year.

Boeing ScanEagle

This catapult-launched spy plane has a 10-foot wingspan and is 4 feet long, and can stay in the air for more than 20 hours. It’s been used in the Iraq war since 2005. It’s equipped with an image-stabilized high-resolution video system that transmits its signal back to its base, which can be 62 miles away. When it’s finally time for it to land, it flies into a catching system called a SkyHook, consisting of 30- to 50-foot pole that snags the plane’s wingtip. Try that with a manned aircraft!

RQ-4 Global Hawk


Called “one of the most coveted pieces of military technology in the world,” this $35 million remotely piloted aircraft is powered by a turbofan engine and is about the size of a fighter plane. It can fly for 12,600 miles at an altitude of up to 65,000 feet for 30 hours. Used primarily for surveillance, its bulbous nose carries classified sensing devices including various GPS devices, infrared cameras, and synthetic aperture radar (SAR) that can see through clouds and even sandstorms. Sending its data back to its base at 50Mb per second, it can precisely identify exactly where moving targets are located. As of this year, the planes have flown for more than 30,000 combat hours.

MQ-9 Reaper

This is the bad boy of the fleet, the hunter-killer UAV that you don’t want to see flying overhead if you’re a bad guy. Two operators at a base in the desert near Las Vegas control this baby via a satellite link, with one piloting the aircraft and another operating its sensors (too bad there’s a lag of 1.2 seconds for their input to reach the Reaper). Its 950hp turbo prop can fly it to an altitude of 60,000 feet, carrying a payload of about 3,000 pounds. On board: a variety of precision-targeted missiles and bombs, along with a camera that can read a license plate from 2 miles away. These drones are capable of autonomous missions, but the Air Force still insists on using human pilots. For now.

X-37B

With its 29-foot length and 14-foot wingspan, the X-37B is a quarter the size of the Space Shuttle. But unlike the shuttle, most of its functions are top secret. In fact, the Air Force didn’t want anyone to know anything about the specific mission of this unmanned military vehicle, which for now will probably be used for various types of surveillance. Strangely enough, the only reason we know anything about it is because it was spotted orbiting high overhead by amateur satellite watchers, who determined it must be on a spy mission because of its telltale routine of passing over the same location on the ground every four days.

X-47B

Behold the future of aerial drones — this one could be the scariest of them all. It’s designed to be launched either from land or catapult-launched from ships, and could be refueled in midair, letting it fly indefinitely. This stealthy 19-foot-long aircraft will have the smarts to carry out its own missions, and the oomph to carry 4,500 pounds of bombs, missiles, and surveillance gear. There’s even talk of loading it up with lasers and microwave weapons. Look out, everyone, because this is the flying killer robot of your nightmares.

Tuesday, September 14, 2010

Converting a Cisco IP Phone from SCCP (Skinny) to SIP Firmware


Converting a Cisco IP Phone from SCCP (Skinny) to SIP Firmware
Categories
Announcements Asterisk Business VoIP Fax over IP Mobile VoIP Open Source VoIP Small Business VoIP Technical Advice trixbox VoIP Commentary VoIP Education VoIP Gateways VoIP Hardware VoIP Interviews VoIP News VoIP Phones VoIP Reviews VoIP Service VoIP Software VoIP Systems
VoIP Buyers Guides
VoIP Systems VoIP Phones VoIP Adapters VoIP Gateways VoIP Headsets Open Source PBX VoIP Networks
Recent posts Recent comments Digium PCI Cards 101 – help for the rest of us….. Uh oh…We let Tom loose. Benefits of 3CX Polycom VVX1500 Overview Upgrading your existing network for VoIP Skype Would Make Great Acquisition for Cisco Polycom HDX 6004 Overview How to Select a Hosted Service Provider
Newsletter
Subscribe to our newsletter and receive weekly updates from VoIP Insider .


Archives
September 2010 August 2010 July 2010 June 2010 May 2010 April 2010 March 2010 January 2010 December 2009 November 2009 October 2009 September 2009 Tech Tip: Converting a Cisco IP Phone from SCCP (Skinny) to SIP Firmware
Posted by Cory Andrews on April 3rd, 2009 in Technical Advice, VoIP Phones4 Comments


Cisco IP Phones are amongst the most popular desktop IP phones out there. By default, Cisco ship their phones from the factory pre-loaded with their proprietary SCCP protocol firmware (also commonly referred to as “skinny”).

If you are running Asterisk, Trixbox, Switchvox or any other standards-based SIP platform or hosted service, you’ll need to migrate your Cisco phone(s) from their native SCCP (skinny) load to SIP in order to use them. While this is not a particularly difficult procedure, it can be frustrating for those who have never attempted the process.

For the purposes of this exercise, we’re using a Cisco CP-7960G. The process may be slightly different depending upon the specific model of Cisco IP phone you are working with.

Cisco 7940/7960 IP phones can support either the Skinny Call Control Protocol (SCCP), Session Initiation Protocol (SIP), or the Media Gateway Control Protocol (MGCP), but not more than one simultaneously. This is possible because they load different firmware versions on bootup. This functionality is transparent to the end user, and you enable it through changes to the basic text−based configuration files that the phones download from a Trivial File Transfer Protocol (TFTP) server.

First, a few prerequisites:

A – You’ll need a CCO login for Cisco.com in order to obtain the latest SIP firmware. The easiest way to obtain a CCO login is to purchase a Smartnet maintenance contract for your Cisco IP phone from an authorized Cisco reseller. Once you have a registered Smartnet, you can obtain CCO login credentials and access the firmware downloads section of Cisco’s website. Expect to pay $8-$15 for a Smartnet contract.

B – You should have a comfort level with basic networking concepts and TFTP setup/administration.

Follow these steps to enable SIP functionality:

Step #1
Download these files from Cisco SIP IP Phone 7940/7960 Software ( registered customers only) and place them in the root directory of your TFTP server (tftpboot on a UNIX machine):

P0S30100.bin This is the SIP image. You’ll want to download the file in binary format, to ensure that it is not corrupted. Note: There are many different variations of this file, depending on the version of software that you are loading.These are some examples:
SIP Release 2.3 or earlier: P0S3xxyy.bin The xx variable is the version number, and yy is the sub−version number.
SIP Release 3.0 and later: P0S3−xx−y−zz.bin The xx variable is the major version number, y is the minor version number, and zz is the sub−version number.
SIP Release 5.0 and later: After this version has been installed, you will not be able to revert back to versions earlier than 5.0. You may still change from SCCP images to SIP images, but they both must be version 5.0 or later. For more information on this, refer to Release Notes for Cisco SIP IP Phone 7940/7960 Release 5.0.
This table describes the meanings of the first 4 characters in the binary files names. Note: To verify which image the phone is using, choose Settings > Status > Firmware Versions. Different phone models use different processors. This fourth digit can help determine the model of phone for which the file is used.

OS79XX.TXT—This file tells the Cisco 7940/7960 which binary to download from the TFTP server. This file is case sensitive and must only contain the name of the file that you want to load, without the .bin extension. For example, if you attempt to load the SIP version 2.3 software, it must contain only the line P0S30203. If you try to load versions 3.0 and later, the file name must be in the format P0S3-xx-y-zz. For example, if you attempt to load the SIP version 7.1 software, OS79XX.TXT must contain the line P0S3-07-1-00. The binary referenced here must also be present in the TFTP root directory. Without this file, the phone does not know which file it needs to retrieve, in order to replace its existing software.
SIPDefaultGeneric.cnf—This file is an example of a default configuration file. This file contains configuration information relevant to all phones.
SIPConfigGeneric.cnf—This file is similar to the previous one, except that it contains information relevant to a specific phone instead of to all phones.
RINGLIST.DAT—Lists audio files that are the custom ring type options for the phones. The audio files listed in the RINGLIST.DAT file must also be in the root directory of the TFTP server.
ringer1.pcm—This file is a sample ring tone that is used by the Cisco 7940/7960.
OS79XX.TXT—This file always contains the universal application loader image.
P003………bin—Nonsecure universal application loader for upgrades from images earlier than 5.x.
P003………sbn—Secure universal application loader for upgrades from images 5.x or later.
P0a3………loads—File that contains the universal application loader and application image, where a represents the protocol of the application image LOADS file: 0 for SCCP, and S for SIP.
P0a3………sb2—Application firmware image, where a represents the application firmware image: 0 for SCCP, and S for SIP.
Step #2
With a text editor (vi or Notepad), rename the file SIPDefaultGeneric.cnf to SIPDefault.cnf (used for global parameters on all phones).

Step #3
With a text editor, rename the file SIPConfigGeneric.cnf to SIPmac_address.cnf, for each phone (for example, SIP002094D245CB.cnf). The MAC address must be specified in capital letters and the extension (.cnf) must be in lower case. The MAC address of the phone can be found on the sticker that is located on the bottom of the phone, or it can be found through the phone LCD screen (choose Settings > Network Configuration > MAC Address). Note: Allow read and write file permissions on the TFTP server for those files.

Step #4
Unplug the power cord or Ethernet cord (if inline power is used) in order to reset the phones. Ensure that the phones can find the TFTP server. Manually configure the phone’s IP address, gateway address, and TFTP server address; or configure the phone network settings from the Dynamic Host Configuration Protocol (DHCP) server. It is recommended that you not use the TFTP server on the Cisco CallManager, if you have one in your current system.

Step #5
Manually Configure the Phone Network Settings

Complete these steps in order to manually configure the phone network settings:

Press the **# buttons in order to unlock the phone. (This step either locks or unlocks the options, based on the current state.)
Press Settings.
Press the down arrow in order to select Network Configuration and press the Select softkey. There is an unlocked padlock icon in the upper-right portion of your LCD.
Use the toggle button and the arrow keys in order to modify any parameters. When you enter IP addresses, the * key is used for decimal points.
Press the Save softkey in order to save your changes.
Step #6 (Optional)
You can also configure the phone network settings from the Dynamic Host Configuration Protocol (DHCP) server. For SIP phones, make sure that the DHCP server uses Option 66 for the TFTP server. These DHCP options are usually configured from the DHCP server:

IP Address (DHCP Option 50)
Subnet Mask (DHCP Option 1)
Default IP Gateway (DHCP Option 3)
DNS Server Address (DHCP Option 6)
TFTP Server (DHCP Option 66)
Domain Name (DHCP Option 15). Note: Cisco CallManager uses Option 150 for the TFTP server, while SIP phones expect Option 66 for the TFTP server.