Merge branch 'dev' of gitee.com:iot-xa2301-fly-noob/c-router-emulator into dev
This commit is contained in:
commit
7caa1be979
74
www/arp.html
74
www/arp.html
|
@ -6,39 +6,63 @@
|
|||
<meta name="author" content="zifan">
|
||||
<meta name="keywords" content="物联网">
|
||||
<title>ARP列表</title>
|
||||
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#arpTable {
|
||||
background-color: rgba(41, 117, 117, 0.667);
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table id="arpTable" width="700" align="center" border="1">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>ip地址</th>
|
||||
<th>mac地址</th>
|
||||
</thead>
|
||||
<tbody id="arpTableBody" align="center">
|
||||
<div></div>
|
||||
<div class="tablecenter">
|
||||
<table id="arpTable" width="700" align="center" border="1" cellspacing="0">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>ip地址</th>
|
||||
<th>mac地址</th>
|
||||
</thead>
|
||||
<tbody id="arpTableBody" align="center">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
fetch("/cgi-bin/ip.cgi").then(resp => resp.json()).then(data => {
|
||||
if (data.code == 0) {
|
||||
arpTableBody.innerText = "";
|
||||
data.data.forEach(rowData => {
|
||||
let tr = document.createElement("tr");
|
||||
let td1 = document.createElement("td");
|
||||
let td2 = document.createElement("td");
|
||||
let td3 = document.createElement("td");
|
||||
fetch("/cgi-bin/arp.cgi").then(resp => resp.json()).then(data => {
|
||||
arpTableBody.innerText = "";
|
||||
data.forEach(rowData => {
|
||||
let tr = document.createElement("tr");
|
||||
let td1 = document.createElement("td");
|
||||
let td2 = document.createElement("td");
|
||||
let td3 = document.createElement("td");
|
||||
|
||||
td1.innerText = rowData.id;
|
||||
td2.innerText = rowData.ip;
|
||||
td3.innerText = rowData.mac;
|
||||
td1.innerText = rowData.id;
|
||||
td2.innerText = rowData.ip;
|
||||
td3.innerText = rowData.mac;
|
||||
|
||||
tr.append(td1, td2, td3);
|
||||
arpTableBody.append(tr);
|
||||
});
|
||||
}
|
||||
})
|
||||
tr.append(td1, td2, td3);
|
||||
arpTableBody.append(tr);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#include <cjson/cJSON.h>
|
||||
#include <mysql/mysql.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
MYSQL *conn;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
|
||||
conn = mysql_init(NULL);
|
||||
if (conn == NULL) {
|
||||
fprintf(stderr, "mysql_init() failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (mysql_real_connect(conn, "localhost", "root", "root", "router", 3306,
|
||||
NULL, 0) == NULL) {
|
||||
fprintf(stderr, "mysql_real_connect() failed\n");
|
||||
mysql_close(conn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (mysql_query(conn, "SELECT * FROM ip_fw")) {
|
||||
fprintf(stderr, "SELECT query failed. Error: %s\n", mysql_error(conn));
|
||||
mysql_close(conn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
res = mysql_store_result(conn);
|
||||
if (res == NULL) {
|
||||
fprintf(stderr, "mysql_store_result() failed\n");
|
||||
mysql_close(conn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cJSON *result_array = cJSON_CreateArray();
|
||||
|
||||
while ((row = mysql_fetch_row(res))) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(item, "id", row[0]);
|
||||
cJSON_AddStringToObject(item, "ip", row[1]);
|
||||
cJSON_AddItemToArray(result_array, item);
|
||||
}
|
||||
|
||||
char *result_json_string = cJSON_Print(result_array);
|
||||
|
||||
printf("Content-Type: application/json;charset=utf-8\r\n");
|
||||
printf("\r\n");
|
||||
printf("%s", result_json_string);
|
||||
|
||||
free(result_json_string);
|
||||
cJSON_Delete(result_array);
|
||||
mysql_free_result(res);
|
||||
mysql_close(conn);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue