查看本地IP地址

有很多小白朋友在使用电脑的时候都很少用到IP地址,只知道有IP地址,但是要如何查看IP地址却不知道。如果你在上网的途中,出现什么问题,我们可以通过IP地址来进行简单的修复。那么要如何查看本地IP地址呢?方法很简单,下面介绍两种简单的查看方法。

Windows

方法一、通过DOS命令查看

1、点击开始——选择运行——在弹出的对话框里输入”cmd“回车,打开CMD窗口。如下图:

2、在弹出的窗口里输入命令:ipconfig/all,然后回车,你就可以看到你本地的IP地址了。如下图:

方法二、通过本地连接查看

1、在桌面网上邻居上点击右键——选择”属性“,打开网络连接窗口——在”本地连接“上点击右键——选择”状态“。如下图:

2、在弹出的本地连接状态窗口里,选择”支持“选项卡,然后你就可以看到你的本地IP地址了。如下图:

3、你还可以点击”详细信息“进入到”网络连接详细信息“窗口查看本地IP地址和DNS服务器等的详细信息。

iOS 获取本地设备IP地址

#import <ifaddrs.h>
#import <arpa/inet.h>
// Get IP Address
- (NSString *)getIPAddress {    
    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    // retrieve the current interfaces - returns 0 on success
    success = getifaddrs(&interfaces);
    if (success == 0) {
        // Loop through linked list of interfaces
        temp_addr = interfaces;
        while(temp_addr != NULL) {
            if(temp_addr->ifa_addr->sa_family == AF_INET) {
                // Check if interface is en0 which is the wifi connection on the iPhone
                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    // Get NSString from C String
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];               
                }
            }
            temp_addr = temp_addr->ifa_next;
        }
    }
    // Free memory
    freeifaddrs(interfaces);
    return address;}
 
 

c#获取本地IP和MAC地址

  1. using System;  
  2. using System.Management;  
  3. using System.Net;  
  4. public class Program  
  5.     {  
  6. static void Main(string[] args)  
  7.         {  
  8. try  
  9.             {  
  10. string ip = "";  
  11. string mac = "";  
  12.                 ManagementClass mc;  
  13. string hostInfo = Dns.GetHostName();  
  14. //IP地址  
  15. //System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;这个过时  
  16.                   System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;  
  17. for (int i = 0; i < addressList.Length; i++)  
  18.                 {  
  19.                     ip = addressList[i].ToString();  
  20.                 }  
  21. //mac地址  
  22.                 mc = new ManagementClass("Win32_NetworkAdapterConfiguration");  
  23.                 ManagementObjectCollection moc = mc.GetInstances();  
  24. foreach (ManagementObject mo in moc)  
  25.                 {  
  26. if (mo["IPEnabled"].ToString() == "True")  
  27.                     {  
  28.                         mac = mo["MacAddress"].ToString();  
  29.                     }  
  30.                 }  
  31. //输出  
  32. string outPutStr = "IP:{0},\n MAC地址:{1}";  
  33.                 outPutStr = string.Format(outPutStr, ip, mac);  
  34.                 Console.WriteLine(outPutStr);  
  35.             }  
  36. catch (Exception e)  
  37.             { }  
  38.             Console.ReadLine();  
  39.         }  
  40.     } 

用java获取本机IP地址

方法一(只能在Windows上使用,Linux平台就gei屁了):

try
{
System.out.println("本机的IP = " + InetAddress.getLocalHost());
} catch (UnknownHostException e)
{
e.printStackTrace();
}

在Linux下的执行结果是:本机的IP = xxx/127.0.1.1 (其中xxx是你的计算机名,偶这里马赛克了)

方法二(可以在Linux下执行)
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements())
{
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
System.out.println(netInterface.getName());
Enumeration addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements())
{
ip = (InetAddress) addresses.nextElement();
if (ip != null && ip instanceof Inet4Address)
{
System.out.println("本机的IP = " + ip.getHostAddress());
}
}
}

posted @ 2016-04-18 13:43  宿命1016  阅读(1096)  评论(0编辑  收藏  举报