相关疑难解决方法(0)

从Docker容器内部,如何连接到本机的本地主机?

所以我在Docker容器中运行了一个Nginx,我在localhost上运行了一个mysql,我想从我的Nginx中连接到MySql.MySql在localhost上运行,而不是将端口暴露给外部世界,所以它绑定在localhost上,而不是绑定在机器的ip地址上.

有没有办法从这个docker容器中连接到这个MySql或localhost上的任何其他程序?

reverse-proxy nginx docker docker-networking

1176
推荐指数
24
解决办法
65万
查看次数

如何在Linux和OS X上获取本地计算机的主IP地址?

我正在寻找一个命令行解决方案,它将返回localhost的主(第一)IP地址,而不是127.0.0.1

该解决方案至少适用于Linux(Debian和RedHat)和OS X 10.7+

我知道ifconfig两者都可用,但它们的输出在这些平台之间并不一致.

unix ip bash ifconfig

318
推荐指数
18
解决办法
49万
查看次数

如何在Python中获取eth0的IP地址?

当Unix上的Python脚本发生错误时,会发送一封电子邮件.

如果IP地址是192.168.100.37(测试服务器),我被要求将{Testing Environment}添加到电子邮件的主题行.通过这种方式,我们可以拥有一个版本的脚本,以及一种判断电子邮件是否来自测试服务器上的混乱数据的方法.

但是,当我谷歌时,我一直在寻找这段代码:

import socket
socket.gethostbyname(socket.gethostname())
Run Code Online (Sandbox Code Playgroud)

但是,这给了我IP地址127.0.1.1.当我使用时,ifconfig我得到了这个

eth0      Link encap:Ethernet  HWaddr 00:1c:c4:2c:c8:3e
          inet addr:192.168.100.37  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:75760697 errors:0 dropped:411180 overruns:0 frame:0
          TX packets:23166399 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:59525958247 (59.5 GB)  TX bytes:10142130096 (10.1 GB)
          Interrupt:19 Memory:f0500000-f0520000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:25573544 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25573544 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:44531490070 (44.5 GB)  TX …
Run Code Online (Sandbox Code Playgroud)

python unix networking nic

62
推荐指数
6
解决办法
15万
查看次数

如何从Mac上的ifconfig获取格式为"Interface:IP Address"的输出

我试图从ifconfig获取以下格式化输出:

en0: 10.52.30.105
en1: 10.52.164.63
Run Code Online (Sandbox Code Playgroud)

我已经能够通过以下命令至少弄清楚如何获取IP地址(除去localhost),但这还不足以满足我的要求:

ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'
Run Code Online (Sandbox Code Playgroud)

谢谢!

regex macos grep ifconfig

4
推荐指数
1
解决办法
1766
查看次数

使用awk或sed从ifconfig解析数据?

我试图用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)

linux awk parsing sed ifconfig

2
推荐指数
2
解决办法
6964
查看次数

标签 统计

ifconfig ×3

unix ×2

awk ×1

bash ×1

docker ×1

docker-networking ×1

grep ×1

ip ×1

linux ×1

macos ×1

networking ×1

nginx ×1

nic ×1

parsing ×1

python ×1

regex ×1

reverse-proxy ×1

sed ×1