Automate Virtual Machine - virtual-machine

I am working on a project that is similiar to Mircosoft Virtual Lab. I have created a .aspx (C#) webpage that is able to run powershell script to launch vmware-vmrc console. The webpage is deployed and run on my own computer. I also have try to publish my solution in a server, webpage work well but console do not appear on my screen. I guess it because the script is running on the server instead of the localhost. I will like to know is there any way to launch the console if my solution/programme is build in the server.
$hostname = "localhost:8333"
$vms = "VmName"
$vm = get-vm $vms
$vmid = $vm.id
$gvm = Get-View $vmid
$vmrc = "C:\Program Files (x86)\Common Files\VMware\VMware Remote Console Plug-in\vmware-vmrc.exe"
$vmrcargs = '-h ' + $hostname + ' -m "' + $gvm.Config.Files.VmPathName + '"'
[Diagnostics.Process]::Start($vmrc, $vmrcargs)

in your code you have the hostname hard coded as localhost, in theory you could read this value from the Request object of ASP.NET context and replace it with the client's host name.
Said so, I really doubt it would work because it's not granted that the server has access to the client remotely... even passing proper IP address, and even if I see there is a port specified (8333), there could be firewalls in the between...
of course in an intranet it could work, you have to try this out.

Perform a telnet on the client's name via the port 8333 to check if the port is open.
If the telnet works, then replace "localhost(or dns or Host name) with the IP of the client"
If the the telnet does not work, then open the port.
However if the port is open, it will work.
Kind Regards,
Garish

Related

Paramiko, opening a SOCKS proxy but from machine B to C

Working on a remote server that doesn't have access to internet. I have 3 machines, A, hasinet and noinet. I want to give noinet access to internet, I succesfully achieved it thanks to this link. (For others interested, don't forget to add the right socks config in your .curlrc if you don't have sudo).
I'm looking how to automate & pythonize this procedure with Paramiko:
machineA$ ssh noinet
noinet$ ssh -D 1080 hasinet
Here's what I came up with:
noinet = paramiko.SSHClient()
noinet.set_missing_host_key_policy(paramiko.AutoAddPolicy())
noinet.connect('noinet', port=22, username='XXX', password='YYY')
noinet_transport = noinet.get_transport()
noinet_channel = noinet_transport.open_channel("direct-tcpip", ("hasinet",22), ("noinet", 22))
hasinet = paramiko.SSHClient()
hasinet.set_missing_host_key_policy(paramiko.AutoAddPolicy())
hasinet.connect('hasinet', username='XXX', password='YYY', sock=noinet_channel)
# Opening a tunnel from noinet to hasinet on port 1080
print("Opening tunnel")
forward_tunnel(1080,"localhost",1080, hasinet.get_transport())
The code doesn't raise any errors, and the original code worked fine when I use only 2 machines. I don't have an SSH server on machine A so I need to serve internet by passing through B, that's why there are 3 machines. If machine B had python I guess it would also be easy (but exposes my password).
The forward_tunnel comes from paramiko's demo examples: https://github.com/paramiko/paramiko/blob/master/demos/forward.py
The tunnel opens fine, the script doesn't raise any error, but the proxy localhost:1080 gives a Connection refused which means the tunnel is not open.

Cannot access Open VPN Management Console via Port Forwarding

I just set up OpenVPN on my Raspberry running headless Raspbian with the server config file provided by my VPN Provider "IP Vanish" and appended the following line in the config file:
management 127.0.0.1 6001 stdin
Afterwards I started the service like this:
sudo openvpn --config PATH/ipvanish-XXX.ovpn
IP Checks yielded that the connection is established as desired.
I want to access the management portal from my Macbook on the same network using port forwarding:
ssh -i XXX.pem -L 3000:localhost:6001 pi#192.168.1.9
The login works fine, but when I go to 127.0.0.1:3000 Safari says
Cancelled load because it is using HTTP/0.9
and Chrome just says that it send an invalid response.
My google research on the "HTTP/0.9" issue didn't really get me anywhere. Is the protocol used for the management portal just too old or what's the real issue here?
Many thanks in advance for any help!
Obviously, I missed that the management interface for openvpn is a COMMAND LINE interface.
A connection with e.g.
nc 127.0.0.1 6001
works just fine.
This answer just in case someone else is under the false assumption, it's a web interface.

IBM Container , "Connection refused" when SSH to the public IP

I'm using IBM Bluemix and Docker.
[My goal] I want to create a container. I found from the website that we could use SSH to login as "root" user. So I guess I could also install maven and MySQL on this container. Though IBM Container is a Docker based file system, we could treat container just like a Linux virtual machine (please correct me if wrong).
I found a similar question here, where njleviere said that port 22 is closed. How do I determine if a port is open or closed? If it's closed, how do I open it? Also, I think that port 22 is actually open in my case.
[Problem Description] I mainly followed this website, but I'm using Ubuntu and SSH instead of Putty.
First, I create the key file with ssh-keygen. For the filename, I tried "cloud" and "cloud.key". Both failed. So I think the name for the key does not matter (please correct me if wrong).
I open the .pub key. There is a "yu#yu-VirtualBox" tag at the end of the key file. I am not sure if I should include this tag. So I tried several things:
ssh-rsa KeyString yu#yu-VirtualBox
ssh-rsa KeyString
KeyString
All failed.
Then I created the container. I choose the "ibmliberty". Given the public IP I created before (already unbind from any containers), I added 22 to the public Port. And pasted the "cloud.pub" to the SSH key. After several minutes, the container started to run. The following two links are the screen shot for the Bluemix console on creating the container.
Then I could see the default page for port 9080 in browser for https://169.44.124.121:9080. It said "Welcome to Liberty" and "WebSphere Application Server V8.5.5.9".
Then I typed (cloud and cloud.pub is the key file)
ssh -i cloud root#169.44.124.121
Then I get the
ssh: connect to host 169.44.124.121 port 22: Connection refused
I used cf ic ps to check the port. It looks fine.
I see 169.44.124.121:22->22/tcp under the PORTS.
Also, I see many programmers use the docker file to launch the IBM Container. Should I switch to docker file instead of this IBM console web interface?
The default ibm-liberty image on bluemix doesn't include sshd. You could add it - you'll need to add supervisord, sshd, and the appropriate configuration for both into your Dockerfile.
Conversely, if what you really want is just a secure command line connection into your container, you can use cf ic exec or docker exec. (e.g. cf ic exec -ti mycontainername bash ) That'll give you a command line without having the overhead (and security exposure) of a running sshd.

could not resolve hostname with scp

I am accessing an ubuntu server over ssh with putty on my windows machine and trying to download a single file to my local windows machine
my windows username is Mark and my hostname per cmd is Marks I am trying the following command on the remote server
scp backup.sql mark#marks:desktop
and I get could not resolve hostname I have tried to put in what I think myip address is and the connection times out
The syntax is this, relative to where you're issuing the command:
scp user#host_from:location/file user#host_to:location/file
And of course if you're local you can omit the user#host prefixes:
scp local_file me#host_to:~/local_file
The direction is always from > to relative to where you issue the command.
binarysubstrate is right about the syntax. The problem is, if the OP puts the name (or address) of his windows client in the 'to' part of the scp command, it probably won't work for a number of reasons:
his windows machine may not have a resolvable FQDN,
his windows machine may be behind a NAT firewall that is not setup to port-forward SSH requests,
he probably does not have an SSH daemon running on his windows machine.
To simply copy a file from the remote server down to a windows client, I would recommend WinSCP.
From the ser you ping your machine name ? Try replace machine name for the IP Address, or add your machine name to hosts configuration file from the server.

How can I set up SSH tunneling to access a webserver behind a firewall?

How would I access a webserver behind a firewall? I'm developing an application for this webserver which is not yet open to the public.
Someone walked me through this before, so I know it can be done. However, it has been about four months and I haven't been able to do it again.
I'm using Putty to connect to the remote machine. From that machine I can open the site http://dev.server.address:83 using Firefox. However, I want to be able to open http://localhost:80 on my machine to see the same page.
I'm using the server address and port 83 for the "source port"
I'm using localhost:80 for the "destination port"
You need to enter "80" into Source port and dev.server.address:83 to Destination.
[And don't forget to click the "Add" button before you leave the configuration screen. If you don't click that, PuTTY doesn't actually create a tunnel. I fell for that gotcha quite a few times myself]
Have you tried using 127.0.0.1:80 instead of localhost:80? I don't use PuTTY, but when I use SSH on my machine, I have to specify 127.0.0.1 instead of localhost.
Do you have a webserver running on your local machine? If that is listening on port 80 http://localhost:80 wont work. Alternatively try mapping the source to a different port (12345 for eg.) and then try http://localhost:12345 in your browser.
On Linux you can also make it happen with:
$ ssh -f -R 83:localhost:80 user#dev.server.address
Provided that you have an SSH account named "user".