linux获取本机ip

ifconfig | grep -i ‘inet addr:‘ | awk ‘{print $2}‘ | awk -F : ‘{print $2}‘ | grep [^127.0.0.1]
时间: 2024-08-02 19:54:52

linux获取本机ip的相关文章

Linux 获取本机IP、MAC地址用法大全

getifaddrs()和struct ifaddrs的使用,获取本机IP ifaddrs结构体定义如下: C代码   struct ifaddrs { struct ifaddrs  *ifa_next;    /* Next item in list */ char            *ifa_name;    /* Name of interface */ unsigned int     ifa_flags;   /* Flags from SIOCGIFFLAGS */ struc

[记]Linux 获取本机(全部)IP、MAC地址方法 (C/C++)

Linux 获取本机IP.MAC地址用法大全 1 2 //#include <sys/types.h> 3 #include <ifaddrs.h> 4 #include <sys/ioctl.h> 5 #include <net/if.h> 6 #include <string.h> 7 #include <stdio.h> 8 #include <unistd.h> 9 #include <netdb.h>

Linux编程获取本机IP地址

使用函数getifaddrs来枚举网卡IP,其中使用到的结构体如下所示: struct ifaddrs { struct ifaddrs *ifa_next; /* Next item in list */ char *ifa_name; /* Name of interface */ unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */ struct sockaddr *ifa_addr; /* Address of interface *

获取本机IP(适用于Linux系统)

/** * @desc 获取本机IP(适用于Linux系统) * @return Ip */ public static String getLocalIP() { String ip = ""; try { Enumeration<?> e1 = (Enumeration<?>) NetworkInterface .getNetworkInterfaces(); while (e1.hasMoreElements()) { NetworkInterface n

Linux下获取本机IP地址的代码

Linux下获取本机IP地址的代码,返回值即为互联网标准点分格式的字符串. #define ETH_NAME "eth0" //获得本机IP地址 char* GetLocalAddress() { int sock; struct sockaddr_in sin; struct ifreq ifr; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) { perror("socket"); return NU

Linux下 shell获取本机ip地址

方法二 /sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" 方法一 获取本机ip地址地址,并保存到变量中 arg=ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " " ipaddr=argechoipadd 这里假设你的 接

python:使用netifaces模块获取本机IP网关等信息

python获取本机IP有很多种方法,可每种方法都有局限性. 使用netifaces模块获取本机IP网关等信息,需要安装netifaces模块,不管windows还是linux都可以通用. 一.程序: #!/usr/bin/env python2 # -*- coding: utf-8 -*- #实现本地网卡IP #需要安装netifaces模块 def GetNetworkIP():     #获取本地网卡IP地址     import netifaces     #routingGatewa

获取本机IP、mac地址、计算机名

python获取本机IP.mac地址.计算机名 在python中获取ip地址和在php中有很大不同,我们先来看一下python 获得本机MAC地址: >>> import uuid >>> def get_mac_address(): mac = uuid.UUID(int = uuid.getnode()).hex[-12:] return ':'.join([mac[e:e+2] for e in range(0,11,2)]) >>> get_m

python获取本机IP、mac地址、计算机名

在python中获取ip地址和在php中有很大不同,在php中往往比较简单.那再python中怎么做呢? 我们先来看一下python 获得本机MAC地址: 1 2 3 4 import uuid def get_mac_address():      mac=uuid.UUID(int = uuid.getnode()).hex[-12:]      return ":".join([mac[e:e+2] for e in range(0,11,2)]) 下面再来看一下python获取