Scanning devices in local network with xamarin (ios) - c#

I would ask if it is possible to get information about connected devices in the local wireless network.
Is there any api for xamarin to do that?

It doesn't seem like Xamarin has an API for this, but Microsoft introduced a Ping (documentation here) and a NetworkInterface class (documentation here) in .NET 2.0 that you could use.
Essentially, what you need to do, is to ping the IP adresses on your local network, which you can do asynchronously using SendAsync(). You then register the callbacks by registering an EventHandler to PingCompleted. The callback will contain a PingCompletedEventArgs which you can use to retrieve basic information (e.g. IP, MAC and Hostname) about the device.
You can find a complete guide of the implementation here.
I hope this helps.
Note: Of course, it all depends on what type of information you expect to retrieve. Although, I think you can only expect to retrieve the basic information about devices on your network, as everything else could potentially be a security risk.
Secondary note: Depending on which devices you wish to discover on your network, you could also use the SNMP component which will allow you to discover devices such as routers, switches, printers, and so on.

I am thinking you are looking for which devices at layer-2 have registered with your wireless controller/accept-point/router and by being connected you are referring to how many have successfully establish 802.x handshake (implying security exchange and channel establishment has occurred).
There exists a tool to do this work (never tested this on my mac) and you can check Flying Squirrel for the above purpose. This will ofcourse be an independent sniffer over the wireless network and you'll require the password used for wifi etc. for making this work.
If you have access to a device that exposes instrumentation (MIB) then you can get that information from the device by SNMP walking the device. At this level you'll of course get the MAC address table and if DHCP is running on your router then perhaps access to DHCP table can give you information about the MAC to IP mapping. On some medium to high end networking gear MIBs like CISCO-DOT11-ASSOCIATION-MIB can be used. Also I am assuming you are refering to 802.11 here there are other wireless protocols like BlueTooth etc. in play as well which use different scanning techniques so the answer depends on what kind of network you are referring to here.

Ok, I figured out a way without snifing the local network. It makes more sense the following way in my case...
Case:
I want to connect to an device which provide an own wlan network. Then I connect to it and pass the home wlan network to it. The device restarts and is now configured as a client in the local home network. And now I need the local ip for service communications.
My Solution:
I do a register call to the device. The device gives me the mac address. Now I register (with phone device) the mac address from the access point device in a online service. After the device has been restarted and get the new local ip address it sends to the online service.
And the I can retrieve the local ip address through polling or through getting push notification from the server...

Related

Is there a way to get the mac addresses and ip of each router connected to a switch?

Like what the title says, is there a way to get the mac addresses and/or ip of all routers connected to a switch in asp.net c#?
If so, is there a way to determine if the connected router is on and off?
The setup of my routers and switch is in the image link.
Managed switches uses SNMP (Simple Network Management Protocol) where you can get information such as the port connection for every port, see here.
Some more information you can get via LLDP (Link Layer Discovery Protocol), see here
I think this should be enough hints. For some work you can use pcap via c#.

How to scan the network to find specific peripheral

I'm creating some small electronic modules for home automation based on Arduino chips, with Ethernet connectivity. I will try to make them get an IP address with DHCP if possible, but I'm also wanting to build a C# application to configure these modules, and I'd like my software to scan the network to auto-detect my modules, as an HP printer driver can auto-detect the printers on the network for instance.
I thought of :
getting the computer's IP and Mask to determine the IP set
then multi-thread pings or HTTP requests to every IP of the set
check the responses and get the mac addresses
see if the mac address matches my set
do an specific http request to retrieve the "model" of the module, and know how to interact with him
Is this algorithm plausible or do anyone know of a more efficient way ? Like broadcasting requests on the broadcast address and see what gets back ? Any samples or ideas ?
Totally plausible. Direct low-level access to put arp requests out and get the arp-table back is little tricky, but there are several questions here on the site.
Be advised that a device does not have to answer to ping to be able to function on the network. Check the documentation on the chips you use.
Assuming you only want to discover over the same network segment, I would actually suggest using a broadcast message instead (UDP). of course you will have to develop the side on the device to respond to that broadcast and listen to those responses. once you get a response, you can start a direct communication to the device using your preferred method.

C# and ActiveSync communication / open and read files

I have a device connected to a host computer through cradle usb. Now, I'm just wondering if I could use C# sockets to communicate with the device (ie device sending data, host computer processing it then replying back to the device). How can I accomplish this? by that, what ip address etc etc.. do I have to change so that it would connect cause I have the sockets working on wireless. If not, then is there a way to connect to the device, open and read a file (a text document to be more specific) from the device to my host application.. any ideas?
Thanks! :)
Depending on your target device, when you connect via ActiveSync it likely makes a local RNDIS network connection between teh two devices. You can resolve "ppp_peer" as the partner's network name instead of trying to use a hard-coded IP address (IIRC the IP is different on XP than on Vista).
Be aware that it's not a full connection. TCP packets gets passed through, but things like ICMP do not.
Of course, this just gives you a socket connection, just like if you were to connect between two PCs. It's not going to allow you to do file system operations unless you have an app on the other side listening for commands. If you want that type of thing, Microsoft provides the Remote API (RAPI) interface (wrapped in managed code here)for a lot of basic commands, and it can be extended (with C) to do anything you'd like.

Multiplayer game

Using either XNA OR just the usual c# win forms application, which would be the best way to create the feature that enables text messages to be sent from me to my friend over the internet?
I don't know if this matters or not, but I now have 3 Mobile Broadband internet... so it's like... Wireless internet, does that matter?
It is quite difficult to "reach your friend over the internet", whatever the framework.
Reaching someone's PC requires knowing the IP address of the destination PC. If the PC is behind a router, the PC most likely has a private IP address, thus is unreachable unless the router implements some form of forwarding (in which case a given TCP port is forwarded to a given PC's internal IP address). Then, you need to configure the router to use DDNS so that your code can get at the router's IP address.
So, it is possible (using the classes mentioned by #Bob), but not for the faint of heart.
The way professional programs (like chat clients) do it is to have a central server that relays messages. The code running on your PC and on your friend's PC sends messages to this server instead of directly to each other, so one doesn't need to know the IP address of the other one. But going this route requires some form of hosting for the server PC.
You could look into the Socket class or the simpler TcpClient and TcpListener. Whether XNA or Winforms shouldn't matter. Using XNA on the Windows platform gives you access to the entirety of the .NET framework, including the networking aspects.
I agree with Timores, you can't directly reach the device of your friend and you will need a server for that. Sockets are not something operators allow when you are connected using 3G and not WIFI.
You are welcome to try if you like the Skiller SDK solution: www.skiller-games.com (full disclosure: I am from Skiller), we have distributed servers so you don't need to host anything and besides other tools you can use the built in social layer where your users will be able to make a list of friends and send messages to each other.
Hope that helps.

Identify user and machine on the local network

In my company we use small application called IPMsg, a messenger kind of tool to pass messages and file to other fellows in company, even it allows to multicast the message.
And also it lists the user name, host name and IP addresses of users.
How can it do that? There is no server present for message routing and when checked through netstat command in CMD it does not show any details like what protocol and port it is using to communicate.
There is source code also available on the same site which is in VC++. I didn't understand a line of code... (I'm a C# guy)
Can anyone explain me how it can do that?
One simple way would be to let the application listen on a certain network port, and when you start your instance of it, it tries to connect to that port on each computer on the same network. If that other computer has that port open, and answers correctly, then you have found another instance of the application.
IPMsg probably multicasts a request for all clients to report their user and host details.
A similar mechanism is used when Windows Explorer attempts to find other machines on a network. A good description of this type of multicasting discovery is described here.
IPMsg is a daemon which listens to incoming connections on a specific port which is the connection port. You can find out which port it used by using Wireshark.
Start wireshark, start listening on the interface where you have connected to LAN and then start sending any message, wireshark will show you the message on the screen with the port number also.
The application is a peer-to-peer software and doesn't require a central server software to route messages. it only has a small daemon which accepts incoming connections. This is the way Jabber Instant messaging protocol also works.
As you said it lists username, hostname and ip address of users, do you mean it pings the network and finds it? If yes, then it is actually possible to find the IP addresses of computers on the Local Network which requires you to know the subnet on which you are connected.
You can use ARP/ICMP Ping to know the hosts present on your network provided you enter the correct subnet information
Multicasting a message is also nothing special. It is a feature provided with all Networking Stacks.
If you want mutlicasting in .NET, it is allowed. Check this page on Code Project which gives a nice example

Categories

Resources