I'd like to detect if Wake On Lan is possible.
On my router (Tomato firmware) there is a table with info - when displays device "Active (In ARP)" - it's possible to turn this device by WOL (offline linux pc).
I wonder if it is achieved by router only function or I can do this in C# or C? Function SendArp can detect MAC adress and do "arping" but it is not what I would like to do.
Your router can't detect if your computer (or any other network device) supports Wake-On-Lan. All your router can do is send out a WOL package and hoping that it will wake up.
If the calling device respects the packet and wakes up must be configured at the device itself and there exists nothing within the OSI layers 4 to 1 which can tell you if a device supports WOL.
If you like to send a WOL packet from your PC using C#, you find plenty examples by using your favourite search engine. Here is one example from Bart de Smet.
Update
The message "Active (In ARP)" doesn't mean that your router detected that it is possible to send a WOL packet. It just tells you that within the routers ARP cache currently is a matching entry for this IP or MAC address. Such a cache has every network device (also your pc). In Windows just open the command line and enter arp -a to see the cache of your windows machine. Here you'll get a list of the stored mac adresses for sending to an IP address. A black hat can try to manipulate this cache to redirect your ip communication. Further informations about this can be found at wikipedia.
So this message just tells you, that your router had recently an ip connection to this device. That's it. But it can't tell you if your device is currently able to handle a WOL packet (cause it is power connected or not).
You're probably best checking out http://msdn.microsoft.com/en-us/library/ff566341(VS.85).aspx
This will let you query boolean for power management and the device specific "wake enabled" state.
Given that it's WMI, you should be able to get to this remotely, but it does need a couple of registry keys set to expose the WMI class.
You get the info about whether a machine supports WOL from the BIOS.
If it is supported, make sure it's turned on. Many machines have the capability disabled by default.
To route WOL packets through the network you need to forward port 9 on the router to 255.255.255.255 (Brodcast-to-all) IP Address.
Related
Here is my problem: My computer is connected to internet with ethernet cable, and also connected to a wifi module. But when I want to send TCP to my module, it always choose ethernet by default.
I have to disconnect my cable to send TCP to my module, but I will need the two connections and know how to swap between them.
How can I choose the interface i want in c#?
Can I swap between them in a single program?
I already use System.Net and the Managed Wifi API.
Thank you for your answers.
Edit:
As #Someprogrammerdude and #sam suggest, i use socket.bind() with the IP address of the default gateway of my wifi to send TCP on it. But when I try to bind, there the requested address is not valid in this context error. So I checked the default gateway address (sry french) :
ipconfig
We can see that my wifi default gateway is 192.168.1.2 and ethernet 192.168.1.1. I tried to put them "manually" but i have the same result.. It cannot be the port i checked myself on the module that he is well opened
Edit 2:
Nvm, i had to bind 192.168.1.100, and not 192.168.1.2. Thank you for your answers, you helped me a lot.
Which interface is used is decided by the local routing table. A cable interface (often) is faster, so it'll get a lower network metric and is subsequently preferred. With DHCP clients, this may also be configured from the DHCP server (if it allows manual settings).
Depending on your system, you can manipulate the interfaces' network metrics (likely need to deactivate DHCP for that) and if you'd like to prefer wireless, just reduce its metric below that of the Ethernet interface. Alternatively, you can add routes to certain services you want to be transferred via wireless to the wireless interface with a lower metric.
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.
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 am using the UDPClient class to send and receive messages on my loopback address. The executables are also interacting with each other. But why doesnt the traffic appear in wireshark?
BTW I am running windows inside parallels on OSX and can select only 1 interface that is my intel pro net network card in wireshark.
Here's the key phrase:
on my loopback address
The loopback address is a complete additional interface, not just an address. Wireshark is configured to listen on a specific interface, and I'm guessing the loopback interface is not it.
The loopback traffic is not captured by the Net Packet Filter driver.
One workaround is to send it to the IP address of your Intel Pro NIC. In my experience, this is enough to hit the NPF capture driver and show up in Wireshark. (Well, to be accurate, my experience in that matter doesn't involve a VM so YMMV).
Of course, the listener should be bound to that NIC IP to receive the packets (and not only to localhost).
I have an embedded system running a web server that will usually be connected to an Ethernet network so users can simply enter the IP address of the device to access it.
However, I also need to make some of the same website functionality avaiable to users of the serial port on the device. It would be nice if I could reuse some of the logic I've developed for the web forms for this.
I am currently using .NET for development on my desktop and my embedded device is Linux based. Is it possible to host website content via a serial port or is there some other means by which I can pull this off?
Just a wild guess: back in the days when you connected by modem to the internet, there was a SLIP protocol: IP over Serial Line. Could you use that to establish an "internet connection" to your device?
There are a few options:
If the server is to be in windows, and you have windows 7 then windows xp mode (1) (2) will allow you to use SLIP so that you can provision over serial as you would to any IP address by mapping the serial port to an IP address.
Alternatively there is a sourceforge project called Contiki which has source code to allow the same if you fancy coding your own (the class is called uIp TCP/IP Stack).
Let me know if this is roughly what you're looking for and I can focus in on your specific requirements if you like:)
Cheers.
The first thing that comes to mind is some sort of LYNX like browser (I don't even know if it exists anymore). Maybe easier would be to just do a simple command line interface? It's linux, so you should just be able to spin up a telnet session pretty easily, right?
I believe you should be able to configure your Linux distribution to point your serial port at a terminal, and have that terminal log in with lynx as the shell.
You might want to follow directions for a Linux serial console (tutorial here) and potentially create a user account with the shell set directly to run lynx. Instruct the login prompt (/etc/issue in the tutorial) with the username and password.
Edit: If you're just looking for some sort of data entry from the console, you could just write a shell script or other program and point that user's shell to that application instead.
You could build a TCP client application on your linux device that will talk to your linux web server and redirect data to serial port, and build a TCP server application for your users that will talk to their serial port and redirect data to some TCP port (like 12345). Then all your users need to do is to set their browser to http://localhost:12345 and connect their PC to linux device via serial port cross over cable.