package geoip;

import java.io.IOException;

import net.webservicex.GeoIP;
import net.webservicex.GetGeoIPDocument;

import org.codehaus.xfire.fault.XFireFault;

public class GetLocation
{
    public static void main(String[] args) 
        throws IOException, XFireFault
    {
        if (args.length == 0)
            System.err.println("You must provide an ip address.");
        
        GeoIPSoapClient client = new GeoIPSoapClient();
        
        if (args.length > 1)
            client.setServiceUrl(args[1]);

        GetGeoIPDocument doc = GetGeoIPDocument.Factory.newInstance();
        doc.addNewGetGeoIP().setIPAddress(args[0]);
        
        GeoIP result =
            client.GetGeoIP(doc).getGetGeoIPResponse().getGetGeoIPResult();
        System.out.println("Your location is: " + result.getCountryName());
    }
}
