代码检测Android设备自己的IP地址? [英] code to detect the Android Device's own Ip Address?

查看:143
本文介绍了代码检测Android设备自己的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道可以检测Android设备的IP地址和Android客户端名称的代码,以便在我们的应用程序中使用此IP地址和客户端名称。

I want to know about the code which can detect the Ip address and the Android client name of the Android Device so that use this Ip Address and client name in our application.

任何人都可以帮助我...
先谢谢。

Can Anyone Help me please... Thanks in Advance.

推荐答案

这会告诉你自己的如果您在Android手机上运行此功能,请使用IP Andress。

This will tell you your own IP Andress if you run this on your Android Phone.

try{
      InetAddress ownIP=InetAddress.getLocalHost();
      System.out.println("IP of my Android := "+ownIP.getHostAddress());
      }catch (Exception e){
      System.out.println("Exception caught ="+e.getMessage());
      }

如果您想知道任何与您绑定的客户的IP地址应用程序

If you want to know the IP address of any the client which binds with your applicaion use

Socket socket = serverSocket.accept();  // accept connection                                            


                    System.out.println("Remote IP:"+socket.getInetAddress());

                    System.out.println("Remote Port:"+socket.getPort());                

这篇关于代码检测Android设备自己的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆