Is there a way to find out whether the current chat session is happening through a VPN connection programatically (using either C# or Java) ?
I don't have access to network tools to do a R&D ( first of all not sure whether it can be tracked live), hence i haven't tried anything.
Any help/pointers/directions will of great help.
Thanks
I believe it would depend on how the VPN is set up.
If the VPN is connected using a software endpoint then it will normally have a simulated network adaptor that you could most likely find the name of (the hardware drivers display name not the connection name) and compare it to a list of known VPN network adaptors.
If the VPN is connected using a hardware endpoint like a firewall or other dedicated network device then there may be no way to tell without some sort of man in the middle hardware approach.
Related
We're developing some hardware devices in our company that need to communicate through TCP on the network with our application. The devices have some restrictions, such as they do not have a display or a dotmatrix to show any current configuration, such as IP or mac address. Therefore, it is not possible to configure the IP configuration directly on the device.
When they are connected to the network for the first time, there is a high chance, that their current network configuration does not match with the network being connected to.
E.g.
They are configured to use DHCP and the network does not provide any DHCP.
They are configured to use a manual IP, such as 192.168.1.1 with a subnet mask of 255.255.0.0, but the network is set up to use 10.X.X.X as IP range with a network mask of 255.0.0.0
We now want to develop a standalone application, that lists all devices being connected to the network and change the IP configuration to a specific one (matching the network needs).
What needs to be set up on the device (running Linux) in order to be capable of the things posted above?
What needs to be set up on the client side application in order to display the devices and reconfigure them if mismatching? The Application should be a .NET WPF / C# application if possible, admin rights can be aquired if needed.
Are there any restrictions / scenarios under which we are not able to detect those devices or set up the new network settings?
Leaving out any security issues I would use a udp broadcast to 255.255.255.255 which will been received by any devices. When you put all valid subnets into the payload the client will know that it is wrongly configured and has to answer back as broadcast (since it might be in a different subnet and a unicast is impossible without any valid routing tables)
But please keep in mind that this can open security issues since you will publish on scans all valid subnets which might been very interesting for attackers.
If you know e.g. the Mac addresses of all possible device you may could encrypt the UDP payload which can only been encrypted with the right Mac addresses.
This is what DHCP, BOOTP, RARP are for. Using DHCP and friends to do this sort of thing means a device plonked on a network stands the best possible chance of getting a valid config in the first place.
If you MUST have your own app doing the management of the issue of IP config, then perhaps consider using the DHCP protocol in your management/server app.
If your devices must not speak to a random DHCP server then consider having them either ignore responses that don't have certain attributes in the reply (bit inefficient since it may keep asking and may tie up IPs) or use DHCP on different ports... At least you're not reinventing the wheel then.
Using existing protocols has the benefit that network analysers can understand what's going on too, system admins can debug and make intuitive guesses as to problems, etc.
I am writing an application in C# and one of the functionality requires to perform different actions based on network connected.
For example;
When PC connected to home network network cable perform MethodA
When PC connected to home network but Wifi then perform MethodB
When PC connected to Office network on building 1 then perform MethodC
When PC connected to Office network on building 2 then perform MethodD
When PC connected to Friends Home network perform MethodE
Here how do I distinguish between different networks?
I would use some information about the network to figure this. If you are on wireless you'll know that the wired nic doesn't have an IP. Then based on the IP scheme you can make an inference of where you are at. You're going to have to know some information about the network.
For example, if your work assigns you an IP in the subnet ranges 10.1.0.1-40 and your home network gives you 192.168.1.2-255 then you can use that information to dictate what your application does.
Unfortunately this is a pretty loose coupling and if the routing scheme changes then your application may break. I'd make this kind of setting configurable, where you create a config that maps ip schemes to "locations" and you use that as your basis of what you do.
If you have your networks mapped to locations in windows you can use the answer in this question to help How do I determine "Network Location" in .NET?.
I believe you could reliably detect whether the machine is connected via wireless or cable to the local router.
However, going further than that I think you'll run into a lot of issues.
If they are on Vista or above you should be able to get the "name" of the network in use. However, this would have to be properly configured AND not jacked with by the end user.
Barring that, you could certainly check the ip address range assigned to you... However that assumes building 1 and 2 issue different ranges and those ranges aren't the same as ones issued by the home network. Further it's entirely likely that the home network and the friends house network are on the same internal range.
I'd say, your application is much better off asking the user what method to use or by giving them the name of the method or by asking some other type of question to give you a hint.
I am currently working on a little chat utility in C#.
The problem is I can't figure out how to scan the network for a specific port on all machines. I am currently using this method
IPGlobalProperties network = IPGlobalProperties.GetIPGlobalProperties();
IEnumerable<IPEndPoint> connections = network.GetActiveTcpListeners()
.Where(x => x.Port == ConstParams.iPort);
where ConstParams.iPort is the port I want to scan (6910 here).
The problem is that the returned values are only local ports and the "0.0.0.0" ip address...
How can I scan for all open ports (6910) on the current network?
Rather than using port scanning, I suggest you to implement a simple discovery mechanism based on multicast/broadcast communication.
During the startup the application should broadcast/multicast its IP/Port information. All running instances should respond to this message with their IP/Port information. This kind of a discovery mechanism is easy to implement, and it is both faster in runtime and more dynamic than the port scanning approach.
You should consider multicast, but rather than rolling your own, rely on an existing standard with library support, like mDNS:
http://en.wikipedia.org/wiki/Multicast_DNS
Or, since you said C#, using one of its native solutions:
http://msdn.microsoft.com/en-us/library/system.net.peertopeer.aspx
Scanning ports is a poor choice, you will most likely trigger firewalls on machines in the network to display your machine as an attacker. Any Intrusion detection systems on the networks could potentially be triggered as well. It's a lot of overhead for what you need.
I would recommend doing a broadcast using UDP or a multicast to discover other clients
http://www.codeproject.com/Articles/1705/IP-Multicasting-in-C
Another option would be to have a centralized server, either on a web server (php script, asp.net page, etc) or a web service (REST) which the chat client would connect to on start up, POSTing it's listening IP/Port, and then in turn would receive a list of all recently announced IP/Ports of the other clients on the network. You'd probably want some keep alive here, IE: the client would POST to the page every 5 minutes, if an IP does not POST for 10 minutes, it would be removed from the list.
To get the public IP of the machine, you could check out this page:
http://www.whatismyip.com/faq/automation.asp
You'd just need to send a web request to it to retrieve the IP. If you want to get the non 0.0.0.0/127.0.0.1 IP of the local interface, you can check out these posts:
Get local IP address
How do I get the Local Network IP address of a computer programmatically? (C#)
GetIPGlobalProperties only returns info about your local machine (see http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getipglobalproperties.aspx ).
To find out which other machines on the network have that port open, you'd have to iterate through the a range of IPs, attempting to connect on that port. There is no central repository to query on this.
This article describes an approach: http://www.dijksterhuis.org/building-a-simple-portscanner-in-c/
this is my first question here, after searching and reading through many places I have not choice but to ask.
I have a C# application that receives data from a GPS device and stored in a database, I need now is to send a string that contains commands which the device should be interpreted.
This device connects to the Internet over GPRS, I haven't idea how to send this packet over TCP over GPRS because the IP is dynamic.
I hope any suggestions or ideas on how to solve this.
Best regards.
You should do it the other way around - the device should poll the server for instructions. Just make sure the server is accessible.
As you have specified that you have developed a C# application to read the GPS data through GPRS that means you are running C# application on a public/static IP.
Nwo as soon as you get a request from the GPRS client, you get the DHCP IP address of the remote endpoint too.
Once you have that endpoint and socket open, you can transmit any data to the GPS device back.
Assuming that your GPS device is having some microcontroller to drive the GSM/GPRS modem.
I'm going to make an assumption here that the 'Device' is some kind of mobile phone connected to a standard GSM network?
If it is, then the short version of the story is "Forget it" even if the IP wasn't dynamic, you simply wouldn't be talking to the IP of your device, you'd actually be talking to the IP address of your providers GGSN, and for a standard consumer connection this is going to be where the buck stops.
Now that said, IF you have the budget, and all your devices (Assuming multiple ones) are with the same carrier, then you can approach the carrier and request a dedicated APN (Access point name) essentially what this is , is the mobile network equivalent of a DNS record, or at least similar enough to use that analogy anyway.
When you set up your data connection on your device you may recall having to enter something like 'pp.vodafone.com' or 'INGhub411.o2-uk.inbound' we'll this is your actual APN, and if you have a custom one they your devices can be set up so that the IP the presents itself at the GGSN actually has a static route back to the individual device in the suppliers GSM network.
As a general rule of thumb however on consumer grade connections this is not enabled and hence there is no ingress available to the individual device.
As zmbq says, the ONLY option you have is for the device to keep polling the server on a regular basis, and yes unfortunately that is going to be very unforgiving on the battery.
of course there is one other way of approaching this, and that's to have the device open a socket directly to your server then keep that socket open. Once the socket is open, 2 way communication can be performed across the link, unfortunately your going to also have to write all the code to manage this connection including, but not limited to monitoring the connection to make sure it's still open and re-establishing it if it's not, something which is incredibly important on a mobile device.
I want to monitor my router to see what is currently being downloaded and what application/Software that initiate it, who is the user doing this and download speedthat user occupy
i got all credential needed for both my wireless connection and the router
any head start for sth like that in C#?
the idea
First of all: Do you even know that your router can do this? Most routers I've seen do not have this level of traffic understanding and management.
If your router does, then there is one of two ways that such data is generally made available:
1) Through a HTTP interface (password protected)
or
2) Through an SNMP interface
To retrieve the appropriate HTTP URL, you simply get it as you would any other web page. Try something like: http://www.csharp-station.com/HowTo/HttpWebFetch.aspx
To retrieve the SNMP settings, there are many options; try this question: What SNMP library for .NET makes traps, sets or gets simple?
However, most likely, your router will not actually have this information available.
So, edit: If your router doesn't support side-chaining, and doesn't support SNMP or similar statistics, then you can't do this in the general sense.
You could spin up a Linux box as the gateway for the machines, and use NAT session statistics to monitor this. The way to do this is to have two network interfaces (logical or physical), one of which gets an IP from your modem, and the other which is the default gateway for the wireless network. Turn on IP forwarding and masquerading (NAT) as well as a DHCP server for the wireless network side. Now, you can use iptables to look at active NAT sessions and how much data has been transferred. You can also use packet filters for more specific information.
Also, if you know which machine is doing the downloading, and are running Windows, you can use WMI ("perfmon.exe" to plot this) to see how much data is being transfered on the actual machine.