Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.Socket;

import android.util.Log;

public class Main {
    private static String TAG = "AveksaUtils";

    public static String getSocketLocalIpAddress() {
        String ipAddress = "";
        Socket socket;
        try {
            socket = new Socket("www.google.com", 80);
            ipAddress = socket.getLocalAddress().toString();
            ipAddress = ipAddress.replace("/", "");
            Log.i(TAG, "IP by socket: " + ipAddress);
            socket.close();
            return ipAddress;
        } catch (Exception e) {
            Log.i(TAG, e.getMessage());
        }
        return ipAddress;
    }
}