Guest User

Untitled

a guest
Jul 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Net;
  4. using System.Net.Sockets;
  5.  
  6. using Hotco.Interfaces;
  7. using OpenNETCF.Net.NetworkInformation;
  8.  
  9. namespace HoTouch.Winforms.Services
  10. {
  11. /// <summary>
  12. /// Description of WifiHelper.
  13. /// </summary>
  14. public class WifiHelper
  15. {
  16. static IPAddress ipa;
  17. static IPEndPoint ipep;
  18. static string oldaddress = null;
  19. public WifiHelper()
  20. {
  21.  
  22. }
  23. public static NetworkStatus Diagnose(string address)
  24. {
  25. var q = address.Split(':');
  26.  
  27. try {
  28. oldaddress = address;
  29. var ip = q[0];
  30. var port = q.Length==2?int.Parse(q[1]):5500;
  31. ipa = new IPAddress(ip.Split('.').Select(n=>byte.Parse(n)).ToArray());
  32. ipep = new IPEndPoint(ipa,port);
  33. if (HoTouch.Core.Services.Impl.TimeOutSocket.Connect(ipep,5000))
  34. return NetworkStatus.Ok;
  35. else
  36. return NetworkStatus.ServerNotAvailable;
  37. }
  38. catch(Exception)
  39. {
  40. if (false && System.Environment.OSVersion.Platform == PlatformID.WinCE)
  41. {
  42. var p = new Ping();
  43. var ni=WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces().Where(x => x is IWirelessNetworkInterface)
  44. .Cast<IWirelessNetworkInterface>()
  45. .FirstOrDefault(x=>x.OperationalStatus!= OperationalStatus.Down);
  46. if (ni == null || ni.SignalStrength.Strength== StrengthType.NoSignal)
  47. return NetworkStatus.WifiNotAvailable;
  48. try
  49. {
  50. if (p.Send(q[0],3).Status != IPStatus.Success)
  51. return NetworkStatus.ServerNotAvailable;
  52. }
  53. catch(Exception)
  54. {
  55. return NetworkStatus.ServerNotAvailable;
  56. }
  57. }
  58. }
  59. return NetworkStatus.MobileServerNotAvailable;
  60. }
  61.  
  62. }
  63. }
Add Comment
Please, Sign In to add comment