查看本地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地址
- using System;
- using System.Management;
- using System.Net;
- public class Program
- {
- static void Main(string[] args)
- {
- try
- {
- string ip = "";
- string mac = "";
- ManagementClass mc;
- string hostInfo = Dns.GetHostName();
- //IP地址
- //System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;这个过时
- System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
- for (int i = 0; i < addressList.Length; i++)
- {
- ip = addressList[i].ToString();
- }
- //mac地址
- mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection moc = mc.GetInstances();
- foreach (ManagementObject mo in moc)
- {
- if (mo["IPEnabled"].ToString() == "True")
- {
- mac = mo["MacAddress"].ToString();
- }
- }
- //输出
- string outPutStr = "IP:{0},\n MAC地址:{1}";
- outPutStr = string.Format(outPutStr, ip, mac);
- Console.WriteLine(outPutStr);
- }
- catch (Exception e)
- { }
- Console.ReadLine();
- }
- }
用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());
}
}
}

浙公网安备 33010602011771号