connect via ssh to virtualbox guest vm without knowing ip address
cat ssh-vm
HOSTIP=`ip route get 1 | awk '{match($0, /.+src\s([.0-9]+)/, a);print a[1];exit}'`
HOST_NETS=`ip addr |grep 192.168.3.33 | awk '{match($0, /.+inet\s([/.0-9]+)/, a);print a[1];exit}'`
HOST_NETS=${HOST_NETS:-192.168.3.0/24}
NETS=${NETS:-$HOST_NETS}
# MAC=${MAC:-08:00:27:7c:55:26}
VBoxManage list vms
USR=${USR:-mxh}
VM1=$(VBoxManage list vms | head -n 1 | awk '{ print $1 }')
VM1=${VM1:-ubuntu-18.04}
VM1=${VM1%\"*}
VM1=${VM1#*\"}
VMID1=$(VBoxManage list vms | head -n 1 | awk '{ print $2 }')
VMID1=${VMID1%\}*}
VMID1=${VMID1#*\{}
VMNAME=${VMNAME:-$VM1}
echo "VM name is: $VMNAME, UUID is: $VMID1"
NIC_MAC=`VBoxManage showvminfo $VMNAME --details 2>&1 | grep 'NIC.*MAC' | sed -re 's/.*MAC: (.+), Attachment.*/\1/' -e 's/(\w{2})/\1:/g' -e 's/:$//'`
MAC=${MAC:-$NIC_MAC}
echo "VM nic MAC is: $MAC"
# VBoxManage guestproperty enumerate $VMNAME
# VBoxManage guestproperty get $VMNAME "/VirtualBox/GuestInfo/Net/1/V4/IP" | awk '{ print($2); }')
# ssh -l USERNAME $VM_IP
# VM_IP=$(vboxmanage guestproperty get "VM_NAME" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print($2); }')
# VBoxManage guestproperty get "CHICAGOVPN" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }' echo "Please to frush arp table in networks($NETS) firstly by run:"
echo "nmap -sP $NETS"
IP=`ip neighbor | grep -i "$MAC" | cut -d" " -f1`
VMIP=${VMIP:-IP}
echo "VM IP is: $IP"
if [ !-n $IP ]; then
echo "VM IP is NULL, exit"
exit 1
fi
echo "Log VM: ssh $USR@$IP"
ssh $USR@$IP
exit 0
# fping -f $NETS
# https://stackoverflow.com/questions/13552881/can-i-determine-the-current-ip-from-a-known-mac-address
IP=`nmap -sP $NETS >/dev/null && arp -an | grep $MAC | awk '{print $2}' | sed 's/[()]//g'`
echo $IP # https://serverfault.com/questions/540107/connect-via-ssh-to-virtualbox-guest-vm-without-knowing-ip-address
# linux vboxmanage show nic mac address
NETS=192.168.3.0/24
# MAC=${MAC:-08:00:27:7c:55:26}
VBoxManage list vms
USR=${USR:-mxh}
VM1=$(VBoxManage list vms | head -n 1 | awk '{ print $1 }')
VM1=${VM1:-ubuntu-18.04}
VM1=${VM1%\"*}
VM1=${VM1#*\"}
VMNAME=${VMNAME:-$VM1}
echo "VM name is: $VMNAME"
NIC_MAC=`VBoxManage showvminfo $VMNAME --details 2>&1 | grep 'NIC.*MAC' | sed -re 's/.*MAC: (.+), Attachment.*/\1/' -e 's/(\w{2})/\1:/g' -e 's/:$//'`
MAC=${MAC:-$NIC_MAC}
echo "VM nic MAC is: $MAC"
# VBoxManage guestproperty enumerate $VMNAME
# VBoxManage guestproperty get $VMNAME "/VirtualBox/GuestInfo/Net/1/V4/IP" | awk '{ print($2); }')
# ssh -l USERNAME $VM_IP
# VM_IP=$(vboxmanage guestproperty get "VM_NAME" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print($2); }')
# VBoxManage guestproperty get "CHICAGOVPN" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }' echo "Please to frush arp table firstly by run:"
echo "nmap -sP $NETS"
IP=`ip neighbor | grep -i "$MAC" | cut -d" " -f1`
VMIP=${VMIP:-IP}
echo "VM IP is: $IP"
if [ -n $IP ]; then
echo "VM IP is NULL, exit"
exit 1
fi
echo "Log VM: ssh $USR@$IP"
ssh $USR@$IP
exit 0
# fping -f $NETS
# https://stackoverflow.com/questions/13552881/can-i-determine-the-current-ip-from-a-known-mac-address
IP=`nmap -sP $NETS >/dev/null && arp -an | grep $MAC | awk '{print $2}' | sed 's/[()]//g'`
echo $IP # https://serverfault.com/questions/540107/connect-via-ssh-to-virtualbox-guest-vm-without-knowing-ip-address
# linux vboxmanage show nic mac address
connect via ssh to virtualbox guest vm without knowing ip address的更多相关文章
- Vagrant Tip: Virtualbox Guest Additions
Vagrant Tip: Virtualbox Guest Additions 12 February 2016 Tired of seeing this message when you run v ...
- Azure PowerShell (12) 通过Azure PowerShell创建SSH登录的Linux VM
<Windows Azure Platform 系列文章目录> 本章将介绍如何使用Azure PowerShell,创建SSH登录的Linux VM 前提要求: 1.安装Azure Pow ...
- Assigning Host USB device to a Guest VM
Example Assigning Host USB device to a Guest VM This example is based on qemu-kvm (0.15.0) as instal ...
- Install VirtualBox Guest Additions for elementary os
Pls refer to: Install VirtualBox Guest Additions for elementary os
- KVM虚拟机IO处理过程(一) ----Guest VM I/O 处理过程
虚拟化技术主要包含三部分内容:CPU虚拟化,内存虚拟化,设备虚拟化.本系列文章主要描述磁盘设备的虚拟化过程,包含了一个读操作的I/O请求如何从Guest Vm到其最终被处理的整个过程.本系列文章中引用 ...
- VirtualBox Guest Additions installation
在使用VirtualBox为CentOS安装增强功能时,输出是: 文本: Verifying archive integrity... All good. Uncompressing VirtualB ...
- SSH连接virtualbox中的虚拟机
SSH连接virtualbox中的虚拟机 SSH 与 Virtualbox 使用virtualbox创建虚拟机进行工作,可以有效地减少本机环境与工作环境之间的相互影响.但Server虚拟机的界面实在太 ...
- openebula vm无法获取IP问题解决
http://archives.opennebula.org/documentation:archives:rel2.2:cong Contextualizing Virtual Machines 2 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法
远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...
随机推荐
- Winform串口编程---接收数据demo(VSPD虚拟串口)
参考地址:https://blog.csdn.net/memgxingfeixiang/article/details/52513970 https://blog.csdn.net/kevin_io ...
- Linux下搭建keepalive+nginx
一. 安装nginx(略) 二. 安装keepalive 下载http://www.keepalived.org/download.html 安装依赖包 yum install –y popt* gc ...
- chrome截屏的方法
原文本文链接:https://blog.csdn.net/xiaofengzhiyu/article/details/94652057 Chrome保存整个网页为图片保存为图片右键检查快捷键Ctrl+ ...
- PAT 1020月饼
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼.现给定所有种类月饼的库存量.总售价.以及市场的最大需求量,请你计算可以获得的最大收益是多少. 注意:销售时允许取出一部分库存.样 ...
- python json库
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写. 1.json库的使用 使用 JSON 函数需要导入 json 库:import jso ...
- Scheduling Tasks
官方文档 https://spring.io/guides/gs/scheduling-tasks/ 官方文档详细介绍了@Scheduled中fixedRate,fixedDelay,cron的用法 ...
- 米尔XC7Z010开发板资源
关于XC7Z010开发板 详细介绍http://www.myir-tech.com/product/myc_C7Z010_20.htm Xilinx基于28nm工艺流程的Zynq-7000 All P ...
- Vulnhub靶场题解
Vulnhub简介 Vulnhub是一个提供各种漏洞环境的靶场平台,供安全爱好者学习渗透使用,大部分环境是做好的虚拟机镜像文件,镜像预先设计了多种漏洞,需要使用VMware或者VirtualBox运行 ...
- Java检查字符串是否包含中文字符
转自:https://blog.csdn.net/zhanghan18333611647/article/details/80038629 强烈推荐一个大神的人工智能的教程:http://www.ca ...
- 5 dex文件
Dex文件中数据结构 类型 含义 u1 等同于uint8_t,表示1字节无符号数 u2 等同于uint16_t,表示2字节的无符号数 u4 等同于uint32_t,表示4字节的无符号数 u8 等同于u ...