1. //
  2. // NetworkInformation.h
  3. //
  4. // Created by akisute on 10/10/07.
  5. // Copyright 2010 株式会社ビープラウド.
  6. /*
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. THE SOFTWARE.
  24. */
  25.  
  26. #import <Foundation/Foundation.h>
  27.  
  28.  
  29. UIKIT_EXTERN const int NetworkInformationInterfaceTypeIPv4;
  30. UIKIT_EXTERN const int NetworkInformationInterfaceTypeMAC;
  31. UIKIT_EXTERN const NSString *NetworkInformationInterfaceAddressKey;
  32.  
  33.  
  34. /*!
  35. @class NetworkInformation
  36. @abstract A singleton class to retrieve network (especially Ethernet) information such as IP address or MAC address.
  37. @discussion This class internally uses <sys/ioctl.h> to retrieve network information.
  38. */
  39. @interface NetworkInformation : NSObject {
  40. /*
  41. This dictionary should be like this:
  42.  
  43. allInterfaces = {
  44. en0 = {
  45. 18 = {
  46. address = "AA:AA:AA:AA:AA:AA";
  47. };
  48. };
  49. en1 = {
  50. 18 = {
  51. address = "BB:BB:BB:BB:BB:BB";
  52. };
  53. 2 = {
  54. address = "192.168.100.20";
  55. };
  56. };
  57. fw0 = {
  58. 18 = {
  59. address = "CC:CC:CC:CC:CC:CC";
  60. };
  61. };
  62. gif0 = {
  63. 18 = {
  64. address = "00:00:00:00:00:00";
  65. };
  66. };
  67. lo0 = {
  68. 18 = {
  69. address = "00:00:00:00:00:00";
  70. };
  71. 2 = {
  72. address = "127.0.0.1";
  73. };
  74. };
  75. stf0 = {
  76. 18 = {
  77. address = "00:00:00:00:00:00";
  78. };
  79. };
  80. vboxnet0 = {
  81. 18 = {
  82. address = "DD:DD:DD:DD:DD:DD";
  83. };
  84. };
  85. }
  86.  
  87. */
  88. NSMutableDictionary *allInterfaces;
  89. }
  90.  
  91. /*!
  92. @property allInterfaceNames
  93. @abstract All existing network interface names.
  94. @discussion Returns NSArray instance which contains NSString objects that represents all exsiting network interface names.
  95. refresh is called if the shared instance have not retrieved network information yet.
  96. */
  97. @property (nonatomic, readonly) NSArray *allInterfaceNames;
  98.  
  99. /*!
  100. @property primaryIPv4Address
  101. @abstract IPv4 address of the primary network interface.
  102. @discussion This property automatically determines which interface is the primary interface and returns its IPv4 address.
  103. refresh is called if the shared instance have not retrieved network information yet.
  104. */
  105. @property (nonatomic, readonly) NSString *primaryIPv4Address;
  106.  
  107. /*!
  108. @property primaryMACAddress
  109. @abstract MAC address of the primary network interface.
  110. @discussion This property automatically determines which interface is the primary interface and returns its MAC address.
  111. refresh is called if the shared instance have not retrieved network information yet.
  112. */
  113. @property (nonatomic, readonly) NSString *primaryMACAddress;
  114.  
  115.  
  116. + (NetworkInformation *)sharedInformation;
  117.  
  118.  
  119. - (void)refresh;
  120. - (NSString *)IPv4AddressForInterfaceName:(NSString *)interfaceName;
  121. - (NSString *)MACAddressForInterfaceName:(NSString *)interfaceName;
  122.  
  123. @end