public String getIP(){
        if(HOSTIP != null){
            return HOSTIP;
        }
        else
        {
            try {
                for (
                    final Enumeration< NetworkInterface > interfaces =
                        NetworkInterface.getNetworkInterfaces( );
                    interfaces.hasMoreElements( );
                )
                {
                    final NetworkInterface cur = interfaces.nextElement( );

                    if ( cur.isLoopback( ) )
                    {
                        continue;
                    }

                    for ( final InterfaceAddress addr : cur.getInterfaceAddresses( ) )
                    {
                        final InetAddress inet_addr = addr.getAddress( );
                        if ( !( inet_addr instanceof Inet4Address ) )
                        {
                            continue;
                        }

                        HOSTIP = inet_addr.getHostAddress();
                        System.out.println("address: " + HOSTIP);
                        
                        jTextField3.setText("Your IP: " + HOSTIP);                        
                        return HOSTIP;
                    }
                }
            } catch (SocketException ex) {
                ex.printStackTrace();
            } 
        }
        
        //default case
        return "";        
    }