7378b4c5eb4a13204c397db679c5c34d1220c07a.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. using System.IO;
  6. using System.Net.Sockets;
  7. using System.Net;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. using System.Net.NetworkInformation;
  11. namespace IControls_FireManager
  12. {
  13. // TCP/IP 공통 루틴은 여기에서 구현한다
  14. public static class _Tcp
  15. {
  16. public static string MyIP()
  17. {
  18. //return Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
  19. string strIP4Address = String.Empty;
  20. foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
  21. {
  22. if (objIP.AddressFamily.ToString() == "InterNetwork")
  23. {
  24. strIP4Address = objIP.ToString();
  25. break;
  26. }
  27. }
  28. return strIP4Address;
  29. //return "192.168.0.2";
  30. }
  31. public static string MyHostName()
  32. {
  33. return Dns.GetHostName();
  34. }
  35. public static string MyDomain()
  36. {
  37. string result = null;
  38. IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
  39. NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
  40. foreach (NetworkInterface adapter in nics)
  41. {
  42. IPInterfaceProperties properties = adapter.GetIPProperties();
  43. foreach (IPAddress address in properties.DnsAddresses)
  44. return result = address.ToString();
  45. }
  46. return result;
  47. }
  48. public static string MyGateWay()
  49. {
  50. try
  51. {
  52. string result = null;
  53. NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
  54. foreach (NetworkInterface adapter in adapters)
  55. {
  56. IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
  57. GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
  58. if (addresses.Count > 0)
  59. {
  60. Console.WriteLine(adapter.Description);
  61. foreach (GatewayIPAddressInformation address in addresses)
  62. result = result + address.Address.ToString();
  63. }
  64. }
  65. return result;
  66. }
  67. catch (Exception e)
  68. {
  69. // LOG
  70. _Event.DebugView_SendMessage_Write(e.ToString());
  71. return null;
  72. }
  73. }
  74. }
  75. }