C Find Computer on LAN With Open Server - c

Im trying to figure out a way for one user to open a server, on a port of their choice, and for a user on the same LAN, to be able to see that server without manually putting in the ip and port. Think like when you open a minecraft LAN server, and people on the LAN can see the server, even though they never put in the ip, and the port is different every time. Is there a way to do this in c on linux with the Berkley Sockets API, with TCP sockets?

There's plenty of articles out there on how to use Unix built-in's to scan your Local Area Network for other hosts.
You can find your own IP address and Network using ifconfig, like in this article.
It's then a simple task to get a list of IP's/hostnames on your LAN using a command like nmap, and then sort through the output.
Here's an example:
sudo nmap -sn 10.84.32.54/24 | grep -Po "(\d{1,3}\.){3}\d{1,3}"
Which will return you a list of ip-addresses on your network like:
10.84.32.1
10.84.32.11
10.84.32.12
10.84.32.14
10.84.32.17
You could then go about scan each of the ports on these by running:
nmap -p- 10.84.32.1
To get an output like:
PORT STATE SERVICE
22/tcp open ssh
2581/tcp open unknown
2443/tcp open unknown

Related

password protection using selenium grid and remote nodes

When using selenium grid with remote nodes, how can I execute commends on the node without passing information in the clear between the grid and the node? I access the site I am testing uses https, so communication between the node and the site is secure, but what about between the hub and the node? Is there any way to secure that? Has anyone tried port forwarding on both the hub and the node?
Thank you. With the help of that link and a little tinkering, I got it to work. In case it helps someone, here is basically what I did. This is the case where I am running the grid on my local machine (at home) and I have nodes running on remote laptops.
Generate an rsa key on the remote machine, and take id_rsa.pub and place it in ~/.ssh/authorized_keys on the local machine running the grid, making sure you have file/directory permissions set correctly
Make sure you have a fixed IP at your local machine, I used the AirPort Utility, under network options, DHCP Reservations. (Info about how to do this is generally easily web-searchable)
Open up port 22 on your local router. I did this using the Airport Utility, network options, Port Settings. At this point you should be able to ssh from the remote machine to the local machine successfully, without using a password.
Start port forwarding on the remote machine, with something like this. ssh -N -L 4444:${HUB_IP}:4444 ${USER_NAME}#${HUB_IP}. Now all data that is sent to port 4444 on the remote machine, will be sent securely to end up on port 4444 on the local machine (this presumes that your grid is set up on 4444)
Start the grid on the local machine, using port 4444
Start the node on the remote machine with the hub setting of -hub http://localhost:4444/grid/register -port {whatever_you_want_for_driver_but_not_4444}
I put this all into a script that runs from the local machine, it calls scripts on the remote machine, so you need to also be able to ssh from the local machine to the remote machine. It is a bit of a hassle to set this up, but once it is done, you can start one script to start the hub and as many nodes as you like.
I think now I can pass information securely between the hub and the nodes.
I have not done this personally, but this link may help you.
For logging into websites, I have usually tried to log in via an API and then insert the cookie into the driver session so logging in was not needed via Selenium.

How do i know the hostname of my NTP server?

I set up a NTP server on my windows machine using the Meinberg Ntp server setup.
I think I have it working, but where do I find the name of the server so I can add it to the config file of the device I want to sync to the server?
You access all network services a computer hosts by its hostname or IP, independent of the protocol. Some services can also be registered in the DNS to make them "discoverable" but normally only networks of a certain size justify the effort involved in setting this up.
Simply determine the hostname of your computer and specify this as the ntp host on your device you want to sync. Perhaps the easiest way to get to the hostname is pressing lWindows + [Pause/Break][1], which shows you the system properties. Should work on most current Windows OSs.

c linux sockets: check for existing connections from client side

I have the following setup:
2 Ubuntu machines (server and client)
on the "server" I'm running this to echo all the data received back to the sender (the client):
ncat -e /bin/cat -v -l 12345
on the client I have simple application which just connects to the remote socket: socket() -> setsockopt() -> connect()
So... my question is: Is it possible to check if there are other applications already connected to the socket from the client application? I want only one process connected to the socket at any given time and I want to check this from the client application. Is this possible? After 3h googling I couldn't find anything relevant :(
(sorry, no experience with network programming)
No, a client is not able to see how many other clients are connected to a server.
To be able to retrieve this information an application specific protocol needs to be used on client and server.
Anyhow there is this one special case: If the client knows that a maximum of N clients can connect to the server, and it's own try to connect is refused it could assume that N clients are connected to the server already.
To set the maximum number of connections ncat handles in parallel use it's option -m/--max-conns. Verbatim form man ncat:
-m numconns, --max-conns numconns (Specify max number of connections) .
The maximum number of simultaneous connections accepted for an Ncat instance. 100 is the default.
Run:
netstat -an | grep <your server port port number>
on your client machine to see any existing TCP connections.
Can you not close the listening socket on the server after you've accepted one client? If there's no listening socket no more clients will be able to connect. Once you've dropped your one client, you can then open the listening socket again, ready for one more. That way the client will see a "failure" to connect if the server is busy, or will succeed normally otherwise.
The down side of this approach is that the client won't be able to determine exactly why it can't connect, it could be because the client is busy (has its one client) or it could be because of other issues. Does this matter?

Client-server in C and ethernet connection

I'm trying to develop a little client-server application in c. For that, I took a source code : http://www.iprelax.fr/outils/c_prog5.php
It's working in local without changing the ip address or the port. I tried with 2 computers (mac os and ubuntu). They are connected with an ethernet cable and we defined a static ip addresses 10.0.0.10 and 10.0.0.20 on this interface (eth0). In the client, we changed the line :
char *msg, *htoname = "127.0.0.1";
with the server ip address but it doesn't work, there is no error.
We tried to change the port number but still the same problem.
We saw anything with the netstat and netcat commands.
How to run the application between 2 computers ?
Thank you for your help
When going between two machines, generally a firewall blocks incoming connections i.e. your server machine should allow client to connect to itself.
If your server is on Ubuntu, you are using Linux IP tables. Either add a rule to allow the server port for incoming connections or disable IP tables entirely.
vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5800 -j ACCEPT
The answer to this question list it in detail
using ip tables on stack overflow

Search for and connect to a local server (C-programming)

I'm doing some socket programming in C where I have one server and many clients on the local network. I want the client to find (search for) the server on the network by itself (i.e.not having to specify the server's address) and connect to it. The protocol between the clients and server should be TCP.
I've been searching the web for some time to find a good solution to this, but haven't found one yet.
Any suggestion to how I would tackle this problem would be greatly appreciated.
An IP and port number is necessary for a client to connect to the game server. However, if the IP address of the server is not available, a 'compromise' could be reached by:
Using a hostname to connect to the server, you can use gethostbyname() to resolve a hostname and obtain the IP address. This should solve the issue if the server's IP is not known or is not static.
Having a process running on a known IP which can give you a list of active servers.
Having the clients scan a particular range of IP addresses instead of trying to connect to a single IP (not a very good idea, but should be doable on a LAN).
Havinh your server broadcast packets (say UDP datagrams) at fixed intervals to all hosts on the current subnet (again not really a good idea, will lead to unnecessary network traffic).
A hybrid approach with more than one of the above could also employed, for example, try connecting via a hostname and if that fails, fallback to connecting to a known IP with list of active servers etc.
If you have control over the network layout and such, I would use a solution involving DHCP and DNS.
Basically, you want to connect your DHCP server to your DNS server so that it would automatically create entries for new computers on the network. This is a feature that most DHCP servers and DNS servers support, including BIND and named and Microsoft's solution.
Then you'll set the server hostname to some known value, and have the clients find the server using DNS. That is, gethostbyname() would work properly so you could use the first bullet point offered in Bhargav's answer.

Resources