这里会显示出您选择的修订版和当前版本之间的差别。
en:arduino:libraries:ethernetipaddress [2016/12/25 22:15] |
en:arduino:libraries:ethernetipaddress [2016/12/25 22:15] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | [[en:arduino:libraries:ethernet|Ethernet]] : IPAddress class | ||
+ | ====== IPAddress() ====== | ||
+ | |||
+ | ===== Description ===== | ||
+ | |||
+ | Defines an IP address. It can be used to declare both local and remote addresses. | ||
+ | ===== Syntax ===== | ||
+ | |||
+ | IPAddress(address); | ||
+ | ===== Parameters ===== | ||
+ | |||
+ | address: a comma delimited list representing the address (4 bytes, ex. 192, 168, 1, 1) | ||
+ | ===== Returns ===== | ||
+ | |||
+ | None | ||
+ | ===== Example ===== | ||
+ | <code cpp> | ||
+ | #include <Ethernet.h> | ||
+ | |||
+ | // network configuration. gateway and subnet are optional. | ||
+ | |||
+ | // the media access control (ethernet hardware) address for the shield: | ||
+ | byte mac[] = { | ||
+ | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | ||
+ | // the router's gateway address: | ||
+ | byte gateway[] = { | ||
+ | 10, 0, 0, 1 }; | ||
+ | // the subnet: | ||
+ | byte subnet[] = { | ||
+ | 255, 255, 0, 0 }; | ||
+ | |||
+ | EthernetServer server = EthernetServer(23); | ||
+ | |||
+ | //the IP address is dependent on your network | ||
+ | IPAddress ip(192,168,1,1); | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | // initialize the ethernet device | ||
+ | Ethernet.begin(mac, ip, gateway, subnet); | ||
+ | |||
+ | // start listening for clients | ||
+ | server.begin(); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | //print out the IP address | ||
+ | Serial.println(myIPaddress); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | [[en:arduino:libraries|Reference Home]] |