Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Don Kuenz, KB7RPU Newsgroups: alt.comp.os.windows-10,alt.sources Subject: Re: Hosts file entries. Date: Wed, 14 Aug 2019 22:34:58 -0000 (UTC) Organization: A noiseless patient Spider Lines: 184 Message-ID: <20190814f@crcomp.net> References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 14 Aug 2019 22:34:58 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="9f9e17e672165c7ddd96a4c5d43480a1"; logging-data="22742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8DP6nq6YTLAAoV4TO7LN8" Cancel-Lock: sha1:oL10s06Q7KUCmskci4/NnsBt5Ic= Xref: csiph.com alt.comp.os.windows-10:96171 alt.sources:1016 Peter Jason wrote: > I am using the hosts file to block unwanted Internet sites, and the > following works so far. Win10 1903 > > ******************************* > # Copyright (c) 1993-2009 Microsoft Corp. > # > # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. > # > # This file contains the mappings of IP addresses to host names. Each > # entry should be kept on an individual line. The IP address should > # be placed in the first column followed by the corresponding host > name. > # The IP address and the host name should be separated by at least one > # space. > # > # Additionally, comments (such as these) may be inserted on individual > # lines or following the machine name denoted by a '#' symbol. > # > # For example: > # > # 102.54.94.97 rhino.acme.com # source server > # 38.25.63.10 x.acme.com # x client host > > # localhost name resolution is handled within DNS itself. > # 127.0.0.1 localhost > # ::1 localhost > > 127.0.0.1 www.expressvpn.com > 127.0.0.1 expressvpn.com > 127.0.0.1 www.ladbrokes.com.au > 127.0.0.1 ladbrokes.com.au > 127.0.0.1 www.get-express-vpn.com > 127.0.0.1 get-express-vpn.com > 127.0.0.1 www.drazens.com > 127.0.0.1 drazens.com > 127.0.0.1 www.nutaku.net > 127.0.0.1 nutaku.com > 127.0.0.1 www.trazens.com > 127.0.0.1 trazens.com > 127.0.0.1 www.velocecdn.com > 127.0.0.1 velocecdn.com > > *********************************************************** > > Is this the correct way to do it; should some entries be on the same > line? That's correct. In ancient days WXP took forever to timeout. So this program below was written by me to correct the situation. Although it used VC back in the day, it ought to be simple enough to port my app to cygwin WIN32. ------------------------------------------------------------------------ #include #include #include #include #define WM_USER_OPEN_IN_OUT WM_USER + 100 #define WM_USER_DO_XCOPY WM_USER + 101 HICON hIconState; HINSTANCE hinst; HWND hwnd; static TCHAR szAppName[] = TEXT("CRCBack"); void thread(PVOID pvoid); LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM); void thread(PVOID pvoid) { char buf[BUFLEN]; int bufLen; char msg404[] = { "HTTP/1.1 404 Not Found\r\n" "Connection: close\r\n" "\r\n" "\n" "\n" "404 Not Found\n" "\n" "

Not Found

\n" "The requested URL was not found on this server.

\n" "


\n" "
send404 server at 127.0.0.1 Port 80
\n" "\n\x0" }; SOCKET sConnect; for (;;) { /* wait for next connection */ sConnect = accept(s, NULL, NULL); if (sConnect == INVALID_SOCKET) { break; } /* receive GET message */ if ((bufLen = recv(sConnect, buf, BUFLEN, 0)) < 0) { break; } /* send 404 message */ if (send(sConnect, msg404, sizeof(msg404), 0) < 0) { break; } /* close connection */ closesocket(sConnect); } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; WNDCLASSA wndclass; hinst = hInstance; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = wndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox (NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT ("CRCBack"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); //ShowWindow(hwnd, SW_SHOW); //UpdateWindow(hwnd); PostMessage(hwnd, WM_USER_OPEN_IN_OUT, 0, 0); PostMessage(hwnd, WM_USER_DO_XCOPY, 0, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CLOSE: break; case WM_CREATE: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_NEXT_XCOPY: if (initSocket() == 0) { _beginthread(thread, 0, NULL); } return 0; } return DefWindowProc(hwnd, message, wParam, lParam); } ------------------------------------------------------------------------ Thank you, 73, -- Don Kuenz KB7RPU There was a young lady named Bright Whose speed was far faster than light; She set out one day In a relative way And returned on the previous night.