我在 Windows PC 上安装了 docker。
我打开控制台并输入docker ps. 该命令工作正常。接下来我尝试执行命令 if config 但没有找到:
$ ifconfig
bash: ifconfig: command not found
Run Code Online (Sandbox Code Playgroud)
是因为Windows的原因吗?
命令docker network ls 也可以正常工作
我试图用sed解析ifconfig输出中的一些数据,但我无法正确执行.我希望命令只提取我之后的数字.
例如,我有兴趣提取发送的字节:
eth1 Link encap:Ethernet HWaddr 00:00:00:09:15:f7
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::92e2:baff:fe08:35c7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:75141 errors:0 dropped:0 overruns:0 frame:0
TX packets:78046 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9040489 (9.0 MB) TX bytes:34806464 (34.8 MB)
Run Code Online (Sandbox Code Playgroud)
如果我使用sed:
ifconfig eth1 | sed 's|.*RX bytes:\([0-9]*\).*|\1|g'
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
eth1 Link encap:Ethernet HWaddr 00:00:00:09:15:f7
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::92e2:baff:fe08:35c7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:75141 errors:0 dropped:0 overruns:0 frame:0
TX packets:78046 errors:0 dropped:0 …Run Code Online (Sandbox Code Playgroud) 我希望在我的一个 shell 脚本中使用我的 eth0 ipv6 地址。我可以使用 ifconfig 和 grep 来检索它,但我确定它一定在某个我没有看到的文本文件中的某个地方,这最终会使检索变得更加容易。有谁知道我应该在哪里看?
谢谢
我有下一个 php 代码:
<?php
$ip = shell_exec("/sbin/ifconfig | grep 'inet:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'");
echo $ip;
?>
Run Code Online (Sandbox Code Playgroud)
当我从命令行运行它时($php5 ip.php),它工作正常,但是当我从浏览器运行它时,它什么也不显示(http://localhost/ip.php)。
顺便说一句,我正在尝试打印我的 IP 地址,但每当我使用时,$_SERVER['SERVER_ADDR'];我都会得到127.0.0.1.
我是套接字编程和阅读Linux网络编程的初学者.我决定实现客户端 - 服务器连接,如本书所示.服务器程序在Ubuntu 14.04机器上运行,客户端代码从Mac机器运行.服务器代码如下
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>
const char message[] = "hello, world\n";
int main()
{
int sock = 0;
int port = 0;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
fprintf(stderr, "failed\n");
else
printf("connection is establisshed\n");
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY );
server.sin_port = 3500;
int status = bind(sock, (struct sockaddr*) &server, sizeof(server));
if (status == 0)
printf("connection completed\n");
else
printf("problem is encountered\n");
status = listen(sock, …Run Code Online (Sandbox Code Playgroud) ifconfig | grep -m1 "inet addr"
Run Code Online (Sandbox Code Playgroud)
Gives me
inet addr:172.30.1.6 Bcast:172.30.140.255 Mask:255.255.252.0
Run Code Online (Sandbox Code Playgroud)
However, I only want the ip, which is 172.30.1.6. How can I do this?
Note that I have to be using ifconfig, as this is an embedded system with limited functionalities.
我正在编写一个#!bin/bashshell脚本来自动化MAC欺骗.在我编写的脚本中,我将输出ifconfig -a | grep HWaddr相当于两个不同的变量.该命令ifconfig -a | grep HWaddr返回
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
Run Code Online (Sandbox Code Playgroud)
和
wlan0 Link uncap: Ethernet HWaddr 00:00:00:00:00:00
Run Code Online (Sandbox Code Playgroud)
但我希望命令返回刚才的MAC地址wlan0.
我对ifconfig输出的所有信息都不感兴趣,我只想知道网络接口及其各自的ip地址.
我可以使用以下命令从ifconfig获取网络接口:
ifconfig |grep " L" | awk '{ print $1}'
Run Code Online (Sandbox Code Playgroud)
eth0 lo tun0
和命令的每个接口的IP地址
ifconfig |grep "inet:" | cut -d: -f2 | awk '{ print $1}'
Run Code Online (Sandbox Code Playgroud)
192.168.0.10 127.0.0.1 10.5.0.13
如何只用一个命令或脚本显示数据,网络接口和IP地址?
eth0 - 192.168.0.10 lo - 127.0.0.1 tun0 - 10.5.0.13