ethercard http\tcp Как посмотреть с какого ip пришел запрос.
- Войдите на сайт для отправки комментариев
Сб, 17/02/2018 - 10:02
#include <EtherCard.h>
static byte myip[] = { 192,168,1,200 };
static byte gwip[] = { 192,168,1,1 };
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"87.103.200.242 \\ in.khai.pw"
"</title></head>"
"<body>"
"<h3>This service is currently unavailable</h3>"
"<p><em>"
"The main server is currently off-line.<br />"
"Please try again later."
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(57600);
Serial.println("\n[backSoon]");
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
Serial.println( "Failed to access Ethernet controller");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
Это пример из библиотеки ethercard BackSoon, как можно посмотреть с какого ip адреса пришел http запрос.
https://jeelabs.org/pub/docs/ethercard/ это ссылка на документацию к этой библиотеке.
Очень жду вашей помощи.
byte sendfiles(char* name) { // function to find the correct header and send a file ether.httpServerReplyAck(); int i = 0; char dtype[13] = ""; while (name[i] != 0) { i++; }//search the end int b = i - 1; while ((name[b] != 46) && (b > 0)) { b--; }//search the point int a = b + 1; while (a < i) { dtype[a - b - 1] = name[a]; a++; } dtype[a - b - 1] = '.'; dtype[a - b] = 'h'; dtype[a - b + 1] = 'e'; dtype[a - b + 2] = 'a'; Serial.println(dtype); // print the requested header file if (streamfile ((char *)dtype, 0) == 0) { streamfile ("txt.hea", 0); } Serial.println(name); // print the requested file if (streamfile ((char *)name, TCP_FLAGS_FIN_V) == 0) { cur = 0; not_found(); } //uncomment this if you want to have printed the ip of the target browser Serial.print("content send to "); for (int i = 30; i < 34; i++) { Serial.print(Ethernet::buffer[i]); if (i < 33) Serial.print("."); } Serial.println(" "); }http://easyelectronics.ru/ethernet-modul-na-enc28j60.html