Txtweb domain info sample code

Txtweb domain info sample code

What is Txtweb ?

Txtweb is a web platform which can be accessed by the sms for free of cost. Here Anyone can deploy any app and which can be accessed worldwide.

Do you want to learn how to program in txtweb ? then Learn and start now.

I have deployed one app named domaininfo in the txtweb and the below is the source code of the app,

package in.javadomain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONException;
import org.json.JSONObject;

public class DomainInfo {

	public static void main(String[] args) {
		DomainInfo pc = new DomainInfo();
		String domainInfo = pc.getDomainName("www.ngdeveloper.com");
		System.out.println(domainInfo);

	}

	public String getDomainName(String domainName) {
		String domainInfo = null;
		try {
			URL url = new URL("http://freegeoip.net/json/ngdeveloper.com");
			URLConnection connection = url.openConnection();
			String line;
			StringBuilder builder = new StringBuilder();
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					connection.getInputStream()));
			while ((line = reader.readLine()) != null) {
				builder.append(line);
			}

			JSONObject json = new JSONObject(builder.toString());

			String ipAddress = "IP Address:" + json.getString("ip") + "<br>";
			String country = "Country Name:" + json.getString("country_name")
					+ "<br>";
			String regionName = "Region:" + json.getString("region_name")
					+ "<br>";
			String city = "City:" + json.getString("city") + "<br>";
			String zipCode = "Zip code:" + json.getString("zipcode") + "<br>";
			double latitude = json.getDouble("latitude");
			String latitudeStr = "Latitude:" + latitude + "<br>";
			double longitude = json.getDouble("longitude");
			String longitudeStr = "Longitude:" + longitude + "<br>";

			String metroCode = "Metro Code:" + json.getString("metro_code")
					+ "<br>";
			String areaCode = "Area Code:" + json.getString("areacode")
					+ "<br>";

			domainInfo = ipAddress + country + regionName + city + zipCode
					+ latitudeStr + longitudeStr + metroCode + areaCode;

		} catch (IOException e) {
			domainInfo = "Server May be Busy, Try Again Later!";
		} catch (JSONException e) {
			domainInfo = "Server May be Busy, Try Again Later!";
		}
		return domainInfo + "<br>" + "App By Javadomain.in";
	}
}

Output:

IP Address:199.79.62.12<br>Country Name:United States<br>Region:Texas<br>City:Austin<br>Zip code:78744<br>Latitude:30.176<br>Longitude:-97.7373<br>Metro Code:635<br>Area Code:512<br><br>App By Javadomain.in

Thanks for reading this article. If you found anything wrong kindly let me know.

351 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *