Make network changes permanent - C++ - c++

I need to allow an external client to change the IP of the Linux machine where the program is running (C++). I already know how to list all the local interfaces and the current IPs assigned to them. I also know how to programatically change said IPs.
What I need to know is how to make this change permanent so, if the machine reboots, it keeps the same network configuration.
What's the best way to do this? Manually parsing /etc/network/interfaces? Calling some linux command?
Edit: I'm using Debian.
Thanks!

Yes, manipulating /etc/network/interfaces is the way to accomplish that (just store the backup in case things go wrong).
Also, if interfaces are managed by network manager (which is rarely the case for servers, but happens on the desktop), you may manipulate it via dbus calls, I think.
You should've mentioned distribution, btw, not the language — if you didn't mention the file it would be impossible to guess ;-)

To make changes permanent, you have to write the network configuration in /etc/network/interfaces and maybe DNS Servers (resolv.conf).
http://wiki.debian.org/NetworkConfiguration
If you don't want to parse the interfaces each time, you could save the IP and Network in a config file to restore it.
Then you have to rewrite "/etc/network/interfaces" only.
After Changes to the network interface configuration, you have to restart the network stack (distro specific).
Restart Interfaces with auto :
$ /etc/init.d/networking restart
Restart other interfaces:
$ ifup [iface]

You can call ifconfig and route commands in a script or better, you can edit the file you mention, depending on your Linux distro.

Related

Packer with vsphere waiting for IP timeout

I am attempting to create VMWare templates using Packer. I have a simple file that is essentially a copy of https://github.com/guillermo-musumeci/packer-vsphere-iso-windows/tree/master/win2019.base.
When I build this it times out at "Waiting for IP".
The network it is using is set for static IP, so I suspect it is that, but how do I define a static IP for this? and does it really need this for template creation?
Thanks
I’ve had similar issues with vsphere-iso packer build. It was caused by using the wrong IP for the HTTP directory especially when I was on my company’s VPN vs being hardwired. Thus, it was continually stuck at 'Waiting for IP'. The issue was the order of priority that packer uses to determine what interface to use for the HTTP directory which contains my kickstarter file. The interface that it was choosing was not accessible from the vsphere instance. Could this be the issue?
How we solved this, is that we actually have a shell wrapper that calls packer. Within that script, we ask the user for an IP that the HTTP directory should be accessed at. I use ifconfig and look at the 10. IP in the list. The shell script passes on that environmental variable to my packer's build.json. Its not the cleanest solution, but Ive been using this fix for months.

Remote launching C++ apps

My problem is simple, I have 1 computer conected to many powerfull servers. I want to execute the app locally but run the process (heavy load) in the remote servers.
The app+settings vary a lot, and I want that this exactly version of the app+settings folder to be used by the remote instances.
My approach so far:
Launch the app locally
Use PSEXEC to remote launch the same executable as it is running in local -> in the servers (with a random port number passed by argument)
Contect to them via sockets
Send commands to execute remotely and get the results
My problem relies in the config files, wich are many(50+) and some of them +4MB. This config files are TXT files in a config folder.
What is the proper way to do it? Is it possible to use PSEXEC to copy remotely a whole folder? Can I do any good trick on the sockets to directly pass a copy of the local files to remote?
I would like all the process to be semi-transparent. Since many people will use it with different versions and settings at the same time. So manually copying the files to 20+servers is NOT an option.
Thank you!
Put the program/script that you want to execute by all machines on one common location on local network (put your configs there too). On all servers create a batch file say 'runme.bat' that will execute your program directly from network location.
This way you can use psexec to run runme.bat essentially executing your program/script on any server you want.
Since often - there are issues using psexec - you may invoke your scripts from Task Scheduler etc.
I do that for 500+ servers and it works. If working for me it will work for you.
You might want to look at HTCondor (http://research.cs.wisc.edu/htcondor/) which could perhaps manage all of this for you.

How to discover all other instances of my application on the local Windows network?

We want to add a 'collaborative' feature to our application, so our program should be able to automatically discover all other instances of itself that are running on the same local network, without needing any extra configuration from the users.
Our application runs on Windows, so it can use any APIs provided by the OS. We are assuming a network typical for a small business, a couple of Windows PCs, some routers, etc.
Also, will there be problems with anti-viruses, firewalls, and such? We don't want to scare our users.
You can send broadcast packets for that but that only works within a single subnet (actually apparently a "broadcast domain" but it's usually the subnet). If you just try every IP you can think of you might trigger firewall pop-ups that suggest that your software is trying to hack the computer. I think the best way is to use broadcast for the current subnet and offer a user interface for adding other hosts.

Deploying a Custom Program to a Hosting Service

I am a total newbie in servers/hosting etc, although I have some experience in programming in C,Java,etc. So excuse me if the question is 'absurd'.
I recently bought service from a hosting site,namely this(hostmds). I have some code I've written in C++ and I want to run it in the hosting site. So my question is:
Is this possible, or will I have to rewrite everything in a new language?
What should my approach be?
Edit: I have a Shared-Hosting account.
You will have to get a "virtual private server" account from your host in order to do this. This will enable you to compile your program on your host machine and run it essentially as if it were a separate machine under your control.
This means you will also be responsible for maintaining your own HTTP server program (such as Apache, if running on a Linux/Unix host), and your own database servers and other support.
If you have a "shared hosting" account (the most common low cost option) with SSH support, you may be able to compile your program, and even run it, but you will be subject to the whims (capricious or otherwise) of the administrators of your system (that it, you may find that libraries you need are removed or moved around)
What type of hosting is this?
What kind of application is this, is it a daemon?
Depending on the amount of access rights you have, you can run the code in the cgi-bin folder or through the shell of the server.
Depending on the OS/compiler you've used to write your code in you might have to modify some things so that it'll work on the target OS. You should probably add some more details. :)
Many hosting services provide CGI/FastCGI/SCGI that can be used for running C++ webapps. However, it depends on your host whether you can actually do this, as it may be difficult to get binaries built on some other system to run on the web hosting service (if you even can upload them in the first place).
On shell services and virtual servers you can also run daemons (that directly listen to a port), but especially on shell services you cannot listen on low ports (0..1024), for security reasons.
Notice that the cheapest hosting packages generally only allow PHP at most, so you will need something more expensive for more access.
It is best to ask the hosting provider for further information, as these things wildly differ from host to another.

how to read list of running processes on a remote computer in C++

What can be done to know and list all running processes on a remote computer?
One idea is to have a server listening to our request on the remote machine and the other one is to use ssh.
The problem is i dont know whether there will be such a server running on the remote machine and i cannot use ssh because it needs authentication.
Is there any other way out ?
If you
cannot install a server program on the remote machine
cannot use anything that requires authentication
then you should not be allowed to know the list of all running processes on a machine. That request would be a security nightmare!
You can do something much simpler without (as many) security problems: scan the publicly-available ports for programs that are running. Programs like nmap.org let you know a fair bit of information about the publicly-running programs on machines.
I have done something similar in the past using SNMP. I don't have the specifics in front of me, but something like "snmpwalk -v2 -c public hostname prTable" got me the process table. I recall later configuring SNMP to generate errors when the number of processes didn't meet our specified requirement, like httpd must have at least 1 and less than 50.
I suggest you look at the code for a remote login, rlogin. You could remotely login to an account that has the privileges that you need. Once logged in, you can fetch a list of processes.
This looks like a good application for a script rather than a C or C++ program.