c - 如何从 shell 脚本或 C 获取传入的 ssh/telnet 客户端本地 IP 地址

标签 c scripting ssh client ip-address

我需要一种方法来获取传入 telnet 或 ssh 的本地(非 WAN)地址 使用 shell 脚本或 C 的 session 。

最佳答案

这可以通过多种方式完成,具体取决于您使用的操作系统/ssh 守护进程/telnet 守护进程。这里有两种方法:

  • OpenSSH 在环境变量 SSH_CLIENT 中发布客户端 ip(和端口)。在 bash 中,您可以使用 ${SSH_CLIENT%% *} 提取 IP。
  • 使用utmpx数据库(与 who 使用的相同),如此处解释:whoamIP - Find hostname/IP of current remote shell user ,或像这样使用 last:last -i1 $USER | awk '{print $3;exit}'

关于c - 如何从 shell 脚本或 C 获取传入的 ssh/telnet 客户端本地 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2428326/

相关文章:

linux - 如何为 SSH_ASKPASS 启动 linux 子 shell 以在 linux 中工作

ssh - GridGain - 通过 Grid.startNodes API 使用 SSH 以编程方式打开节点

c - 不使用平方根的两点之间的距离

c - VIM 语法 : conditional function coloring

c - 使用 ncurses 显示数独网格

bash - shell 脚本中的单行 if 语句不起作用

networking - Mikrotik 脚本 : Get Interface IP

c++ - char argv[][7] 和 char *argv[] 的区别

windows - Windows 上的关机脚本删除注册表项?

php - CURL setopt无法正常工作