Mấy modem gpon của nhà mạng mới bị đổ cấu hình. Còn xài router tự cung tự cấp, modem nhà mạng bridge rồi thì k bị nữamodem t chặn 2 domain này chưa bao giờ bị đổi dns cả, lên app my viettel nó nhận sai luôn S/N modem![]()
View attachment 2089089Code:viettelhomewifi.com viettelacs.vn
View attachment 2089123
đây router nhà mạng đó thímMấy modem gpon của nhà mạng mới bị đổ cấu hình. Còn xài router tự cung tự cấp, modem nhà mạng bridge rồi thì k bị nữa
Router nhà mạng nhìn “chuyên nghiệp” vậy! Thấy giờ viettel đổi modem có logo với giao diện đơn giản hơn vầy nhiều lắm. Mà 2 tên miền ở trên đề cập check k có IPđây router nhà mạng đó thím![]()
router này mới nhận tháng 1 năm nay ấy thímRouter nhà mạng nhìn “chuyên nghiệp” vậy! Thấy giờ viettel đổi modem có logo với giao diện đơn giản hơn vầy nhiều lắm. Mà 2 tên miền ở trên đề cập check k có IP
addEventListener('scheduled', (event) => {
event.waitUntil(handleRequest());
});
addEventListener('fetch', (event) => {
return event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const accountEmail = '';
const accountId= '';
const apiToken = '';
const domain = '';
const ip = await resolveDomain(domain);
if (ip) {
console.log(`The IP address of ${domain} is: ${ip}`);
const locationId = await getLocationId(accountId, apiToken, accountEmail);
if (locationId) {
console.log(`The location ID is: ${locationId}`);
const updateResult = await updateLocation(accountId, apiToken, locationId, ip, accountEmail);
if (updateResult) {
console.log("Update location successful:");
console.log(`Location ID: ${updateResult.id}`);
console.log(`Name: ${updateResult.name}`);
console.log(`IP: ${updateResult.networks[0].network}`);
console.log(`Subnet: ${updateResult.networks[0].network.split('/')[1]}`);
console.log(`Created At: ${updateResult.created_at}`);
console.log(`Updated At: ${updateResult.updated_at}`);
} else {
console.log("No location data found.");
}
} else {
console.log("No locations found.");
}
} else {
console.log(`Failed to resolve the IP address of ${domain}`);
}
return new Response('Worker execution completed', { status: 200 });
}
async function resolveDomain(domain) {
const apiURL = 'https://dns.google.com/resolve';
const queryURL = new URL(apiURL);
queryURL.searchParams.append('name', domain);
queryURL.searchParams.append('type', 'A');
const response = await fetch(queryURL);
const data = await response.json();
if (data.Answer instanceof Array && data.Answer.length > 0) {
const ipAddresses = data.Answer
.filter(answer => answer.type === 1)
.map(answer => answer.data);
return ipAddresses[0] || null;
} else {
return null;
}
}
async function getLocationId(accountId, apiToken, accountEmail) {
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/gateway/locations`;
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json',
'X-Auth-Email': accountEmail,
'X-Auth-Key': apiToken
}
});
if (response.ok) {
const data = await response.json();
const result = data.result;
return result.length > 0 ? result[0].id : null;
} else {
return null;
}
}
async function updateLocation(accountId, apiToken, locationId, ip, accountEmail) {
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/gateway/locations/${locationId}`;
const response = await fetch(url, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json',
'X-Auth-Email': accountEmail,
'X-Auth-Key': apiToken
},
body: JSON.stringify({
client_default: true,
ecs_support: true,
name: 'Home',
networks: [
{ network: `${ip}/32` }
]
})
});
if (response.ok) {
const data = await response.json();
return data.result || null;
} else {
return null;
}
}
Fen cho mình thắc mắc xíu, mình lấy dns trên CF gắn thẳng vào dns trong router nhà mình, kiểm tra thử các thiết bị kết nối thì đều được gán dns auto đúng luôn, thì làm các bước như fen có sự khác biệt gì vậy ạ?Cập nhật code update IP từ DDNS lên Cloudflare để set DNS cho tất cả các thiết bị trong nhà (lên router, thiết bị) không cần DoH, DoT:
JavaScript:addEventListener('scheduled', (event) => { event.waitUntil(handleRequest()); }); addEventListener('fetch', (event) => { return event.respondWith(handleRequest(event.request)); }); async function handleRequest(request) { const accountEmail = ''; const accountId= ''; const apiToken = ''; const domain = ''; const ip = await resolveDomain(domain); if (ip) { console.log(`The IP address of ${domain} is: ${ip}`); const locationId = await getLocationId(accountId, apiToken, accountEmail); if (locationId) { console.log(`The location ID is: ${locationId}`); const updateResult = await updateLocation(accountId, apiToken, locationId, ip, accountEmail); if (updateResult) { console.log("Update location successful:"); console.log(`Location ID: ${updateResult.id}`); console.log(`Name: ${updateResult.name}`); console.log(`IP: ${updateResult.networks[0].network}`); console.log(`Subnet: ${updateResult.networks[0].network.split('/')[1]}`); console.log(`Created At: ${updateResult.created_at}`); console.log(`Updated At: ${updateResult.updated_at}`); } else { console.log("No location data found."); } } else { console.log("No locations found."); } } else { console.log(`Failed to resolve the IP address of ${domain}`); } return new Response('Worker execution completed', { status: 200 }); } async function resolveDomain(domain) { const apiURL = 'https://dns.google.com/resolve'; const queryURL = new URL(apiURL); queryURL.searchParams.append('name', domain); queryURL.searchParams.append('type', 'A'); const response = await fetch(queryURL); const data = await response.json(); if (data.Answer instanceof Array && data.Answer.length > 0) { const ipAddresses = data.Answer .filter(answer => answer.type === 1) .map(answer => answer.data); return ipAddresses[0] || null; } else { return null; } } async function getLocationId(accountId, apiToken, accountEmail) { const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/gateway/locations`; const response = await fetch(url, { headers: { 'Authorization': `Bearer ${apiToken}`, 'Content-Type': 'application/json', 'X-Auth-Email': accountEmail, 'X-Auth-Key': apiToken } }); if (response.ok) { const data = await response.json(); const result = data.result; return result.length > 0 ? result[0].id : null; } else { return null; } } async function updateLocation(accountId, apiToken, locationId, ip, accountEmail) { const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/gateway/locations/${locationId}`; const response = await fetch(url, { method: 'PUT', headers: { 'Authorization': `Bearer ${apiToken}`, 'Content-Type': 'application/json', 'X-Auth-Email': accountEmail, 'X-Auth-Key': apiToken }, body: JSON.stringify({ client_default: true, ecs_support: true, name: 'Home', networks: [ { network: `${ip}/32` } ] }) }); if (response.ok) { const data = await response.json(); return data.result || null; } else { return null; } }
Không có gì khác biệt nếu bạn không reboot modem nhà mạng, vì đa phần các gói cho cá nhân hiện nay tại VN đều là IP động, tức là IP sẽ bị thay đổi nếu có sự cố hoặc khởi động lại modem, mà ip trong CF cần phải chính xác IP mà b đang xử dụng để xác định đúng profile, IP khác là profile khác. Nếu nhà b dùng gói ip tĩnh thì không cần quan tâm vấn đề nàyFen cho mình thắc mắc xíu, mình lấy dns trên CF gắn thẳng vào dns trong router nhà mình, kiểm tra thử các thiết bị kết nối thì đều được gán dns auto đúng luôn, thì làm các bước như fen có sự khác biệt gì vậy ạ?
Thanks fen nhiều.
fen ơi b1 tạo worker ở đâu thía? mình kiếm ko thấyTui xem chùa bấy lâu nay mới reg acc bác ơi
Setup thử đi bác mướt lắm
Ý bạn hỏi cái này hảfen ơi b1 tạo worker ở đâu thía? mình kiếm ko thấy
đúng rùi fen ơi, mình tạo trên cloudfare luôn mà mò nãy giờ ko thấy mục nào edit codeÝ bạn hỏi cái này hả
https://voz.vn/t/huong-dan-dung-cloudflare-zero-trust.822971/post-27865653
Bạn nhấn overview rồi create workerđúng rùi fen ơi, mình tạo trên cloudfare luôn mà mò nãy giờ ko thấy mục nào edit code
View attachment 2089764
Thanks fen, mình làm đc rùi. Mục đích của cái này là để tự update ip của router theo ddns phải ko fenBạn nhấn overview rồi create worker
Deploy code mẫu xong sửa lại cũng được
View attachment 2089773
Đúng r bác ơiThanks fen, mình làm đc rùi. Mục đích của cái này là để tự update ip của router theo ddns phải ko fen
Tốc độ phản hồi nhanh, dùng được tất cả các thiết bị mạng trong nhà, khoong cần add thủ công từng thiết bị mất thời gian, sử dụng worker chung tài khoản với cloudflare dễ kiểm soát nha bác ơiFen cho mình thắc mắc xíu, mình lấy dns trên CF gắn thẳng vào dns trong router nhà mình, kiểm tra thử các thiết bị kết nối thì đều được gán dns auto đúng luôn, thì làm các bước như fen có sự khác biệt gì vậy ạ?
Thanks fen nhiều.
bác chắc chắn IP của nhà bác trùng với Source IPv4 trên Cloudflare chưasao mình gán dns của nextdns vào router thì chặn dc quảng cáo còn gán dns của CF vào router thì chỉ chặn dc 3% thui nhỉ các fen @@ trên iphone vẫn phải xài profile CF mới chặn dc
sure lun rùi bác, e gán ddns cả cho nextdns và CF mà, e còn cẩn thận check ip lại trên trang getip.pro nữa.bác chắc chắn IP của nhà bác trùng với Source IPv4 trên Cloudflare chưa
Bác vào conversation check tin nhắn e gửi ultra em xem giúp cho bácsure lun rùi bác, e gán ddns cả cho nextdns và CF mà, e còn cẩn thận check ip lại trên trang getip.pro nữa.
Kỳ lạ ta