I want to retrieve the client PC information at the sender end. When a client sends a request/message at client end in simple socket programming lets say, i want that client to retrieve the information of client PC e.g like which windows is client using , what is the name of client's PC etc.
I have retrieved client IP address using
connectionSocekt.RemoteEndPoint.ToString();
I have searched whole internet and YouTube But i couldn't find any where how to retrieve other information of client PC. Kindly help me with this thing.
There are many ways to get information about a remote host on your local network.
You will NOT necessarily get it from some arbitrary "sockets" program: a basic TCP/IP connection simply doesn't have that information .
A client request to a web server, however, might have some of what you're looking for. Look at HTTP headers, particularly the User-Agent header.
Since you're on Windows, you should also look at WMI: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page
Related
I have a server application which monitors the clients' activities in the network (all codes are in C# winforms). The server application already has IP addresses of client computers. I want to know how to check
i) if the clients are online (i.e, have opened and been using the client applications) or offline (not using the applications)?
ii) if the clients' computers are opened?
I'm not good in networking and have not got it after searching for hours on internet. Please help!
Edited: I have seen the mentions of HTTP, TCP, UDP, etc. in various sites about server-client applications. What are the differences between them and which one should be used for the above?
PS: Sorry for extra questions. The questions are related so I dont want to make a new post.
You could check if the client machines are online by pinging each machines using their respective IP address.
Ping ping = new Ping();
PingReply pingReply = ping.Send("IP Address");
if(pingReply.Status == IPStatus.Success)
{
//Machine is online
}
To check if client machines are using any particular application(if
those application are built by you and have access to source code).
you can use WCF inter process communication. basically you will create
a WCF service method and host in a managed environment. to be specific
you could host this service in your server win form application. As
long as your win form application is running in the server client
application installed in individual machines can call this method to
send a status(including individual IP address of machines). so server
app would know who is running/opened the specific client application
in each machine.
If you want to check the status of any other client applications, say
you want to get the status to server whenever a client machine runs a
"xyz" application. then you need a create a application which runs on
individual client machines(Windows service would be best option). job
of this application would be to check the running processes
periodically to see if any specific application process is running. if
then it will invoke the WCF hosted in your server app to send the
status.
Several options are available, following is a conceptual answer
Your server can maintain available clients in some list. Here you can include Time to live for a specific client (Like session expiring). You client need to send periodical flags to server to indicate that Client is still using the service and when Server get this reply it can update it list's session so it won't be expire.
Note - The list can be a small data structure which include clients IP and Last flag recieved time. Your server then can go through this list and check for expiration of a client (lets say when time stamp is older than 2 minutes Server assumes client doesn't use the service/not online)
Also other option is your server can send client a flag and get reply back periodically.
Simple Client Server -
http://www.codeproject.com/Articles/12286/Simple-Client-server-Interactions-using-C [Simple guide]
http://csharp.net-informations.com/communications/csharp-multi-threaded-server-socket.htm [Multi threaded]
Using some code from codeproject, I converted a LAN scanner into an ASP.NET web application. The app attempts to ping all ips in a given user inputted range. The app works fine locally. However, I wanted to make the app online. Using the free AZURE subscription, I put the site online. However, it does not scan the user's LAN. This might be because it is trying to scan the LAN of the server computer my app is deployed on. I would like to know if using ASP.NET, it is possible to scan the CLIENT'S LAN instead of the SERVER'S LAN. Please comment if you require the code for the webpage. The website should be online at http://nkdscan.azurewebsites.net/index . Please comment if any other info is required.
No, this is not possible using a server-based scanner, because that server has no way to access the private IP addresses used by the local network. You can only do this from the inside of a network, which means client-side code of some sort.
The problem is that your local network addresses (192.168.., 10...*, etc) are not accessible from the other side of your router. When you connect to a remote server your router does some address translations to make it look like it's sending the request. If you have lots of computers in the same LAN connecting to the same server it's going to look very much like lots of connections from the same place.
If you want build internet server applications then you need to know the basics of how the internet works, and this is one of the important ones. You don't have to know how things happen at the packet level (although that's interesting too), but some understanding of things like network address translation is essential.
I'm a little confused when it comes to socket servers in terms of deploying it online.
Running locally is fine as most tutorials get you to make a server application and a client application which I can execute. Done all that for awhile now and I'm happy with it but now I want to try it using a web host.
How would I deploy the socket server to my web host and then run the server? do I just upload the program to the server and run www.mywebpage.com/mysocketserver (assuming the program is called mysocketserver.exe)
may sound like a stupid question but I'm having one of those brain dead moments.
[Edit]
Great answers guys thank you. Shame I can only mark one as the answer.
Most hosting services are website related: you upload your website to their server and the host takes care of provisioning the application.
However you haven't written a website that is served by a web server, but a socket server, which is more akin to the web server itself that runs a website.
As a result you will need a host that will allow you to install and run applications, such as a Virtual Private Server service, rent a physical server or use a cloud service such as Amazon EC2.
You usually Remote Desktop or SSH into the server you are renting (or own) to upload and start the application either as a normal application, a Service or a Daemon.
Once you have installed your socket server on the host server and started the application running you should be able to contact your service using the IP address for your server and the port that you are running your socket server on.
For example, if your ip address is 10.0.0.1 and you've written your socket server to listen on port 1234, you should be able to contact your service at address 10.0.0.1:1234.
Take into account firewalls allowing access to that port.
You will also then be able to use a DNS service such as DynDns to assign a domain name to that ip address.
You can't do that unless your socket server is using HTTP as a protocol.
You are using a port for your server, right? The ports are used to identify which application to talk with.
When you browse the web using "http://something" you really say let me get the stuff which can be found on the IP 1.2.3.4 (DNS lookup) using port 80 (which is registered for HTTP). You don't have to specify the port in the browser since all browsers know that HTTP uses port 80.
So what you are really should do is to put the socket server on your host and tell your customers/users that they can connect to your socket server at port XXX on host "www.mywebpage.com".
If you've built a client you'll just hard code the port in it or specify the default port automatically.
The problem in the Internet is the routing/name translation, so that mywebpage gets translated into the correct IP address.
Either your webserver needs a fixed public IP address or you need to use a service like dynds which will dynamically map your changing IP address to the static name.
I want to know how I can send or recieve data over internet to/from a computer in subnet
(this is specially in context to PPP users bcoz getting static IP is not so much in practice).
I actually want to create an application which can transfer file between 2 specific computer in WAN.
so what are things I need to know about to do the same..(ex. PRESENT IP or MAC ADDRESS etc..)
PROGRAMATICAL EXPLANATION ALTHOUGH PREFFERED,BUT IS NOT NECCESARY...
FTP?
There is a vast torrent of useful results in google, I seriously suggest to google before you ask here.
For instance, have a look at the top result: http://www.devarticles.com/c/a/C-Sharp/Network-Programming-in-C-sharp/
Apart from that, FTP, as suggested by Colin, may be what you're looking for. If you're new to using FTP in C# have a look at http://www.google.com/search?q=c%23+ftp
Put the information on a public IP server, so both computers keep polling if there is new data and send / download that data as needed. A single text file can hold necessary flags such as paths and other info you need.
server just need to be a web server, which means IIS or similar should be installed.
I'm thinking part of your question has to do with one of the computers not having a static IP address. If the two computers, A & B, don't know each others IP address, then an alternative is to use a server. Either A can store the information on the server to be picked up by B, or A can register his current IP address on the server for B to lookup and then connect to A, assuming firewalls don't interfere. Another scheme is that A and B can simultaneously connect to the server, and the server can relay data between the two.
Of course, all of this communication would be done using techniques such as those suggested by mafutrct and Colin.
This question sounds to me like the difficulties of NAT Traversal and trying to establish peer-to-peer connectivity over the Internet. I stumbled on this question researching the best way to set up Internet connectivity to a device that is sitting behind a firewall. I am assuming that the device behind the firewall has to initiate the connection, that a Internet server application (on a Public IP address) to at least manage the initiation of the connection is required, and the Internet server application may also have to act as a relay if the difficulties of NAT is not able to be traversed.
http://en.wikipedia.org/wiki/NAT_traversal
http://en.wikipedia.org/wiki/Peer-to-peer
A good example of this is LogMeIn. Where the application is installed on the computer that needs to be accessible over the Internet, that application communicates with the LogMeIn Internet servers, you can establish a connection to that computer either by initiating through the LogMeIn servers and connecting peer-to-peer over port 80/443 using NAT Traversal (this would be establishing a peer-to-peer connection) or by initiating through the LogMeIn server and the LogMeIn server acting as a relay if peer-to-peer is unable to be established.
Please note; you must have an application (something running) on both ends of the connection on the Internet, there is no other way. Just like FTP that was mentioned earlier (FTP Client, FTP Server)... but in this case it is peer-to-peer (basically you are writing your own Client and Server... or if you have to use a relay... Client--Relay--Server
http://en.wikipedia.org/wiki/LogMeIn
"The service connects the remote desktop and the local computer using SSL over TCP or UDP and utilizing NAT traversal techniques to achieve peer-to-peer connectivity when available."
The part I don't know is can the relay go in both directions; and I am figuring the device behind the firewall must have to constantly manage the open connection to the Internet Server that is the relay. Those are the questions I am wrestling with now.
Also, you may want to check out this post.
C# byte streams through TCP
From that time, till this date I have encounter so many problems with these four kinds of NAT that basically without an external server you cant do anything.
This is because, one computer can never find where the other one is located as suggested in the pic.
Here PC 'A' will never come to know about the port that corresponds to PC 'B' on R2B without an external server.Even more, if somehow u come to know about the ports you are still in a situation that the router wont allow you to access it if the request hasn't been made for your IP.
I am developing an application which has one web server and one C# client which posts XML to the web server. The web server needs to know the local IP address of client. I tried methods to retrieve the IP address at the server side, but these methods don't give the IP address of the client when there are proxy servers or NAT in between. So I need to find the local IP of the connection at the client application and send it with the request.
The problem is in HttpWebRequest. I don't see any method by which I can get the local IP address of the connection made while sending HTTP request.
CLARIFICATION:
The client in my case is not browser-based. It is a C# application. My server has specific rules based on local IP, that was are used to connect to the server while sending the HTTP request. In my case, local IPs are fixed. There could be multiple IPs on a local machine -- that's why I want the local IP associated with the Socket used to send the request. This can be solved if I use TcpClient in C# and implement the HTTP protocol on top of it, but I want to avoid that. So, is there any way I can get the socket associated with HttpWebRequest before posting the request?
It is not possible to get the local IPAddress of the connection that HttpWebRequest is going to use. However, you could use Dns or System.Net.NetworkInformation class to get all the local IPaddresses, and send them as a custom header with your request. On the server side you could parse this header, and see if any of the IP's match the one that you are expecting.
However, as Damien has indicated above, this solution is not foolproof, people could spoof the IPaddress to the one the server is expecting. Maybe you need to take a step back and think what security you are trying to achive by this? And see if you could accomplish your goals by a different method - for eg: user Authentication using a supported method like Basic(over HTTPS), Digest, NTLM, Kerberos, Negotiate, or use SSL with client certs?
One possible solution is to tell the client what ip it should use when connecting to the server, and include that ip in a custom header for the server to read.
var srcip = IPAddress.Parse("10.0.0.1");
var request = (HttpWebRequest)HttpWebRequest.Create ("http://example.com/");
request.Headers.Add("X-Original-Client-IP", srcip.ToString());
request.ServicePoint.BindIPEndPointDelegate = delegate { return new IPEndPoint(srcip, 0); };
request.GetResponse();
There's no guaranteed way of doing this. Javascript and server-side code can only see the public address, not the local one. There is a method for getting it using Java (mentioned here), but it relies on both Javascript and Java being available, and the user's browser supporting that particular call.
Given that many local IPs are assigned as needed (my home PC's is assigned using DHCP, my work PC's changes occasonally too), do you think knowing the local IP would actually be any use?
Maybe you should move from HttpWebRequest to SOAP requests/responses if XML is what you send over the line. Implement ASPX web service or WFC webservice. HttpWebRequest are always seen to the server as they are coming from the last IP that issued them so that would be NAT or proxy.
However, I too find it odd enough that you need to know local machine IP on the server side.