Something I believe is really useful on a mobile device, is a portable network scanner.
I’ve got this on my android tablet (currently using “Fing“) and sometimes this comes in handy (especially on mobile devices because of their lack on native network discovery abilities)
So I started my search on the WP7 marketplace.
There are a couple of apps promising “ping”-like functions on the WP7 platform.
But after testing them one by one, they all failed…
A couple of them created the impression that they worked, but in the end they didn’t…
So, let’s create our own 🙂
so, some background.
According to wikipedia, Ping is created in 1983 and is used to check network connectivity.
When you “ping” a network devices, it “pongs” back (replies), and you know it’s available to
communicate with you.
Ping is based on ICMP echo requests.
ICMP on it’s turn is defined in RFC 792 of the IETF
Its an OSI layer 4 function, and works on top of IP.
So, basically, if we want to create our WP7 network discovery app, we need to create an IPv4 packet, put in a ICMP request, and broadcast it around. 🙂
a bitter reality
In .net 4.5, you have the “ping” class.
This is an incredible easy way of achieve our target.
But it’s not part of the “mobile” silverlight based SDK for wp 7.1…
The other way around: what do we have.
Since 7.1 (Mango) we have sockets!
A nice explanation is written here at msdn.
What if we want to craft our own ICMP packet?
You just need a byte array, put it in an IP packet, and solved!
Anyway, you can spawn a network socket with multiple arguments.
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
AddressFamily:ip4, ip6, unspecified or unknown
SocketType: stream (tcp) dgram (udp) or unknown
ProtocolType: tcp, udp, unspecified or unknown
And of course, unspecified and unknown is not supported on WP7.
So,we only have tcp and udp available…
No ICMP or even RAW as in the full desktop version of a socket…
Some guys on the internet say ping should work with tcp/udp on port 7…
Knowing this can’t actually work, I experimented with it anyway.
Result: udp doing nothing – tcp replying sometimes (absolutely not trustworthy)
Any suggestions from somewhere? Is it even possible using only TCP/UDP/WP7?
‘cause I’m out idea’s…