1 const SYDNEY_ORIGIN = 'https://sydney.bing.com';
2 const KEEP_REQ_HEADERS = [
10 'sec-websocket-extensions',
12 'sec-websocket-version',
16 'access-control-request-headers',
17 'access-control-request-method',
20 ['3.2.50.0', '3.5.31.255'], //192,000
21 ['3.12.0.0', '3.23.255.255'], //786,432
22 ['3.30.0.0', '3.33.34.255'], //205,568
23 ['3.40.0.0', '3.63.255.255'], //1,572,864
24 ['3.80.0.0', '3.95.255.255'], //1,048,576
25 ['3.100.0.0', '3.103.255.255'], //262,144
26 ['3.116.0.0', '3.119.255.255'], //262,144
27 ['3.128.0.0', '3.247.255.255'], //7,864,320
36 const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
43 const ipToInt = (ip) => {
44 const ipArr = ip.split('.');
46 result += +ipArr[0] << 24;
47 result += +ipArr[1] << 16;
48 result += +ipArr[2] << 8;
55 * @param {number} intIP
58 const intToIp = (intIP) => {
59 return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`;
62 const getRandomIP = () => {
63 const randIndex = getRandomInt(0, IP_RANGE.length);
64 const startIp = IP_RANGE[randIndex][0];
65 const endIp = IP_RANGE[randIndex][1];
66 const startIPInt = ipToInt(startIp);
67 const endIPInt = ipToInt(endIp);
68 const randomInt = getRandomInt(startIPInt, endIPInt);
69 const randomIP = intToIp(randomInt);
76 * @param {Request} request
81 async fetch(request, env, ctx) {
82 const currentUrl = new URL(request.url);
83 const targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search);
85 const newHeaders = new Headers();
86 request.headers.forEach((value, key) => {
87 // console.log(`old : ${key} : ${value}`);
88 if (KEEP_REQ_HEADERS.includes(key)) {
89 newHeaders.set(key, value);
92 newHeaders.set('host', targetUrl.host);
93 newHeaders.set('origin', targetUrl.origin);
94 newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI');
95 const randIP = getRandomIP();
96 // console.log('randIP : ', randIP);
97 newHeaders.set('X-Forwarded-For', randIP);
98 const oldUA = request.headers.get('user-agent');
99 const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android');
103 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012'
106 newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35');
109 // newHeaders.forEach((value, key) => console.log(`${key} : ${value}`));
110 const newReq = new Request(targetUrl, {
111 method: request.method,
115 // console.log('request url : ', newReq.url);
116 const res = await fetch(newReq);