#include<SPI.h>#include<Ethernet.h>// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};//the IP address for the shield:
byteip[]={10,0,0,177};voidsetup(){Ethernet.begin(mac,ip);}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}Ethernet.begin(mac,ip);Serial.print("The DNS server IP address is: ");Serial.println(Ethernet.dnsServerIP());}voidloop(){}
Ethernet.gatewayIP()
名称
Ethernet.gatewayIP()
説明
デバイスに設定された、ゲートウェイのIPアドレスを取得する。
書式
IPAddress EthernetClass::gatewayIP();
引数
なし。
戻り値
デバイスに設定された、ゲートウェイのIPアドレス。
使用例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}Ethernet.begin(mac,ip);Serial.print("The gateway IP address is: ");Serial.println(Ethernet.gatewayIP());}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}Ethernet.begin(mac,ip);if(Ethernet.hardwareStatus()==EthernetNoHardware){Serial.println("Ethernet shield was not found.");}elseif(Ethernet.hardwareStatus()==EthernetW5100){Serial.println("W5100 Ethernet controller detected.");}elseif(Ethernet.hardwareStatus()==EthernetW5200){Serial.println("W5200 Ethernet controller detected.");}elseif(Ethernet.hardwareStatus()==EthernetW5500){Serial.println("W5500 Ethernet controller detected.");}}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Ethernet.init(53);// use pin 53 for Ethernet CS
Ethernet.begin(mac,ip);}voidloop(){}
#include<SPI.h>#include<Ethernet.h>voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}}voidloop(){if(Ethernet.linkStatus()==Unknown){Serial.println("Link status unknown. Link status detection is only available with W5200 and W5500.");}elseif(Ethernet.linkStatus()==LinkON){Serial.println("Link status: On");}elseif(Ethernet.linkStatus()==LinkOFF){Serial.println("Link status: Off");}}
#include<SPI.h>#include<Ethernet.h>// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
bytemac[]={0x00,0xAA,0xBB,0xCC,0xDE,0x02};// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClientclient;voidsetup(){// start the serial library:
Serial.begin(9600);// start the Ethernet connection:
if(Ethernet.begin(mac)==0){Serial.println("Failed to configure Ethernet using DHCP");// no point in carrying on, so do nothing forevermore:
for(;;);}// print your local IP address:
Serial.println(Ethernet.localIP());}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}Ethernet.begin(mac,ip);bytemacBuffer[6];// create a buffer to hold the MAC address
Ethernet.MACAddress(macBuffer);// fill the buffer
Serial.print("The MAC address is: ");for(byteoctet=0;octet<6;octet++){Serial.print(macBuffer[octet],HEX);if(octet<5){Serial.print('-');}}}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);IPAddressmyDns(192,168,1,1);voidsetup(){Ethernet.begin(mac,ip,myDns);IPAddressnewDns(192,168,1,1);Ethernet.setDnsServerIP(newDns);// change the DNS server IP address
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);IPAddressmyDns(192,168,1,1);IPAddressgateway(192,168,1,1);voidsetup(){Ethernet.begin(mac,ip,myDns,gateway);IPAddressnewGateway(192,168,100,1);Ethernet.setGatewayIP(newGateway);// change the gateway IP address
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Ethernet.begin(mac,ip);IPAddressnewIp(10,0,0,178);Ethernet.setLocalIP(newIp);// change the IP address
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Ethernet.begin(mac,ip);bytenewMac[]={0x00,0xAA,0xBB,0xCC,0xDE,0x02};Ethernet.setMACAddress(newMac);// change the MAC address
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Ethernet.begin(mac,ip);Ethernet.setRetransmissionCount(1);// configure the Ethernet controller to only attempt one transmission before giving up
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Ethernet.begin(mac,ip);Ethernet.setRetransmissionTimeout(50);// set the Ethernet controller's timeout to 50 ms
}voidloop(){}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);IPAddressmyDns(192,168,1,1);IPAddressgateway(192,168,1,1);IPAddresssubnet(255,255,0,0);voidsetup(){Ethernet.begin(mac,ip,myDns,gateway,subnet);IPAddressnewSubnet(255,255,255,0);Ethernet.setSubnetMask(newSubnet);// change the subnet mask
}voidloop(){}
Ethernet.subnetMask()
名称
Ethernet.subnetMask()
説明
デバイスのサブネットマスクを返却する。
書式
IPAddress EthernetClass::subnetMask();
引数
なし。
戻り値
デバイスのサブネットマスク。
使用例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);voidsetup(){Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}Ethernet.begin(mac,ip);Serial.print("The subnet mask is: ");Serial.println(Ethernet.subnetMask());}voidloop(){}
#include<SPI.h>#include<Ethernet.h>// network configuration. dns server, gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};// the dns server ip
IPAddressdnServer(192,168,0,1);// the router's gateway address:
IPAddressgateway(192,168,0,1);// the subnet:
IPAddresssubnet(255,255,255,0);//the IP address is dependent on your network
IPAddressip(192,168,0,2);voidsetup(){Serial.begin(9600);// initialize the ethernet device
Ethernet.begin(mac,ip,dnServer,gateway,subnet);//print out the IP address
Serial.print("IP = ");Serial.println(Ethernet.localIP());}voidloop(){}
#include<SPI.h>#include<Ethernet.h>// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};//the IP address for the shield:
byteip[]={10,0,0,177};// the router's gateway address:
bytegateway[]={10,0,0,1};// the subnet:
bytesubnet[]={255,255,0,0};// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// initialize the ethernet device
Ethernet.begin(mac,ip,gateway,subnet);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client==true){// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());}}
#include<SPI.h>#include<Ethernet.h>// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};//the IP address for the shield:
byteip[]={10,0,0,177};// the router's gateway address:
bytegateway[]={10,0,0,1};// the subnet:
bytesubnet[]={255,255,0,0};// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// initialize the ethernet device
Ethernet.begin(mac,ip,gateway,subnet);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client==true){// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());}}
#include<SPI.h>#include<Ethernet.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,69,104);// telnet defaults to port 23
EthernetServerserver(23);EthernetClientclients[8];voidsetup(){Ethernet.begin(mac,ip);// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// start listening for clients
server.begin();}voidloop(){// check for any new client connecting, and say hello (before any incoming data)
EthernetClientnewClient=server.accept();if(newClient){for(bytei=0;i<8;i++){if(!clients[i]){newClient.print("Hello, client number: ");newClient.println(i);// Once we "accept", the client is no longer tracked by EthernetServer
// so we must store it into our list of clients
clients[i]=newClient;break;}}}// check for incoming data from all clients
for(bytei=0;i<8;i++){while(clients[i]&&clients[i].available()>0){// read incoming data from the client
Serial.write(clients[i].read());}}// stop any clients which disconnect
for(bytei=0;i<8;i++){if(clients[i]&&!clients[i].connected()){clients[i].stop();}}}
#include<Ethernet.h>#include<SPI.h>// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};//the IP address for the shield:
byteip[]={10,0,0,177};// the router's gateway address:
bytegateway[]={10,0,0,1};// the subnet:
bytesubnet[]={255,255,0,0};// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// initialize the ethernet device
Ethernet.begin(mac,ip,gateway,subnet);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client){// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// initialize the Ethernet device
Ethernet.begin(mac,ip);// start listening for clients
server.begin();}voidloop(){if(server){Serial.println("Server is listening");}else{Serial.println("Server is not listening");}}
#include<SPI.h>#include<Ethernet.h>// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};//the IP address for the shield:
byteip[]={10,0,0,177};// the router's gateway address:
bytegateway[]={10,0,0,1};// the subnet:
bytesubnet[]={255,255,0,0};// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// initialize the ethernet device
Ethernet.begin(mac,ip,gateway,subnet);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client==true){// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};byteip[]={10,0,0,177};byteserver[]={64,233,187,99};// Google
EthernetClientclient;voidsetup(){Ethernet.begin(mac,ip);Serial.begin(9600);delay(1000);Serial.println("connecting...");while(!client){;// wait until there is a client connected to proceed
}if(client.connect(server,80)){Serial.println("connected");client.println("GET /search?q=arduino HTTP/1.0");client.println();}else{Serial.println("connection failed");}}voidloop(){if(client.available()){charc=client.read();Serial.print(c);}if(!client.connected()){Serial.println();Serial.println("disconnecting.");client.stop();for(;;);}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// initialize the Ethernet device
Ethernet.begin(mac,ip);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client){Serial.print("Client is connected on port: ");Serial.println(client.localPort());client.stop();}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// initialize the Ethernet device
Ethernet.begin(mac,ip);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client){Serial.print("Remote IP address: ");Serial.println(client.remoteIP());client.stop();}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// initialize the Ethernet device
Ethernet.begin(mac,ip);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client){Serial.print("Remote port: ");Serial.println(client.remotePort());client.stop();}}
#include<Ethernet.h>#include<SPI.h>bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(10,0,0,177);// telnet defaults to port 23
EthernetServerserver=EthernetServer(23);voidsetup(){// Open serial communications and wait for port to open:
Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}// initialize the Ethernet device
Ethernet.begin(mac,ip);// start listening for clients
server.begin();}voidloop(){// if an incoming client connects, there will be bytes available to read:
EthernetClientclient=server.available();if(client){client.setConnectionTimeout(100);// set the timeout duration for client.connect() and client.stop()
}}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;charpacketBuffer[UDP_TX_PACKET_MAX_SIZE];//buffer to hold incoming packet,
voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){intpacketSize=Udp.parsePacket();if(packetSize){Serial.print("Received packet of size ");Serial.println(packetSize);Serial.print("From ");IPAddressremote=Udp.remoteIP();for(inti=0;i<4;i++){Serial.print(remote[i],DEC);if(i<3){Serial.print(".");}}Serial.print(", port ");Serial.println(Udp.remotePort());// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);Serial.println("Contents:");Serial.println(packetBuffer);}}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){Udp.beginPacket(Udp.remoteIP(),Udp.remotePort());Udp.write("hello");Udp.endPacket();}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){Udp.beginPacket(Udp.remoteIP(),Udp.remotePort());Udp.write("hello");Udp.endPacket();}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){Udp.beginPacket(Udp.remoteIP(),Udp.remotePort());Udp.write("hello");Udp.endPacket();}
#include<SPI.h> // needed for Arduino versions later than 0018#include<Ethernet.h>#include<EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);Serial.begin(9600);}voidloop(){// if there's data available, read a packet
intpacketSize=Udp.parsePacket();if(packetSize){Serial.print("Received packet of size ");Serial.println(packetSize);}delay(10);}
#include<SPI.h> #include<Ethernet.h>#include<EthernetUdp.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
bytemac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};IPAddressip(192,168,1,177);unsignedintlocalPort=8888;// local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDPUdp;charpacketBuffer[UDP_TX_PACKET_MAX_SIZE];//buffer to hold incoming packet,
voidsetup(){// start the Ethernet and UDP:
Ethernet.begin(mac,ip);Udp.begin(localPort);}voidloop(){intpacketSize=Udp.parsePacket();if(Udp.available()){Serial.print("Received packet of size ");Serial.println(packetSize);Serial.print("From ");IPAddressremote=Udp.remoteIP();for(inti=0;i<4;i++){Serial.print(remote[i],DEC);if(i<3){Serial.print(".");}}Serial.print(", port ");Serial.println(Udp.remotePort());// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);Serial.println("Contents:");Serial.println(packetBuffer);}}