- Proxy Sunucusu Kullanarak Trafiği Dinlemek:
Proxy sunucusu kullanarak trafiği dinlemek için popüler bir kütüphane olan http-proxy'yi kullanabilirsiniz. İşte basit bir örnek:
const http = require('http');
const httpProxy = require('http-proxy');
const proxy = httpProxy.createProxyServer({});
const server = http.createServer((req, res) => {
// HTTP isteklerini proxy sunucusuna yönlendirin
proxy.web(req, res, { target: 'http://hedef-sunucu-adresi' });
});
server.listen(8080, () => {
console.log('Proxy sunucusu dinleniyor: [url]http://localhost:8080');[/url]
});
proxy.on('proxyReq', (proxyReq, req) => {
console.log('Gönderilen istek: ', req.url);
});
proxy.on('proxyRes', (proxyRes, req, res) => {
console.log('Alınan yanıt: ', req.url);
});
HTTP İsteklerini Yakalayarak Trafiği Dinlemek:
const http = require('http');
const server = http.createServer((req, res) => {
// HTTP isteklerini yakala ve logla
console.log('Gelen istek: ', req.method, req.url);
// Hedef sunucuya isteği yönlendirin
// Burada hedef sunucu ile isteği iletebilirsiniz
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Merhaba, dünya!\n');
});
server.listen(8080, () => {
console.log('Sunucu dinleniyor: [url]http://localhost:8080');[/url]
});