Recent

Author Topic: how to disable internet access  (Read 3175 times)

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
how to disable internet access
« on: February 24, 2018, 01:05:12 am »
Good friends, a consultation.
how can I disable internet access, from any browser

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how to disable internet access
« Reply #1 on: February 24, 2018, 01:19:46 am »
local firewall. you block access for all application to everything except your LAN.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: how to disable internet access
« Reply #2 on: February 24, 2018, 01:42:32 am »
thank you friend, then one option would be to add browsers to the firewall list ...

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: how to disable internet access
« Reply #3 on: February 24, 2018, 05:29:29 am »
Disable all network controllers and modems...  :D
// BTW: normally a good firewall should block out of the box everything, so if you don't setup a rule for a browser everything is fine without doing anything...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: how to disable internet access
« Reply #4 on: February 24, 2018, 02:25:35 pm »
good friends, at the moment I just got this code that blocks the internet for all browsers  :) , at least while the program is open.

this is the code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes,
  9.   SysUtils,
  10.   FileUtil,
  11.  
  12.   netblock, // add this unit
  13.  
  14.   Forms,
  15.   Controls,
  16.   Graphics,
  17.   Dialogs, StdCtrls;
  18.  
  19. type
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     Button1: TButton;
  25.     Button2: TButton;
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure Button2Click(Sender: TObject);
  28.   private
  29.     { private declarations }
  30.   public
  31.     { public declarations }
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41. { TForm1 }
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);  // Block All Connections
  44. var
  45.   nbiStart: TNetBlockInfo;
  46. begin
  47.   nbiStart.dwBlockMode:=NB_BLOCK_INTERNET; // Blocking type
  48.   nbiStart.dwResolution:=20; // Timer event delay
  49.   SetNetBlock(@nbiStart);
  50. End;
  51.  
  52. procedure TForm1.Button2Click(Sender: TObject);  // Unblock All Connections
  53. begin
  54.    StopNetBlock;
  55. end;
  56.  
  57. end.

netblock.pas    (unit)

Code: Pascal  [Select][+][-]
  1. unit netblock;
  2. {$mode delphi}
  3. ////////////////////////////////////////////////////////////////////////////////
  4. //
  5. //    Unit           :  NETBLOCK
  6. //   Date           :  05.25.2004
  7. //    Description    :  TCPIP network connection blocking unit
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////
  10. interface
  11.  
  12. ////////////////////////////////////////////////////////////////////////////////
  13. //    Include units
  14. ////////////////////////////////////////////////////////////////////////////////
  15. uses
  16.    Windows,
  17.   MMSystem;
  18.  
  19. ////////////////////////////////////////////////////////////////////////////////
  20. //    IPHLPAPI data structures
  21. ////////////////////////////////////////////////////////////////////////////////
  22. type
  23.    PMIB_TCPROW       =  ^MIB_TCPROW;
  24.   MIB_TCPROW        =  packed  record
  25.      dwState:       DWORD;
  26.      dwLocalAddr:   DWORD;
  27.       dwLocalPort:   DWORD;
  28.      dwRemoteAddr:  DWORD;
  29.       dwRemotePort:  DWORD;
  30.   end;
  31.  
  32.   PMIB_TCPTABLE     =   ^MIB_TCPTABLE;
  33.   MIB_TCPTABLE      =  packed record
  34.       dwNumEntries:  DWORD;
  35.      Table:         Array [0..MaxWord] of  MIB_TCPROW;
  36.   end;
  37.  
  38. type
  39.   TGetTcpTable      =   function(pTcpTable: PMIB_TCPTABLE; dwSize: PDWORD; bOrder: BOOL):  DWORD; stdcall;
  40.   TSetTcpEntry      =  function(pTcpRow:  PMIB_TCPROW): DWORD; stdcall;
  41.  
  42. ////////////////////////////////////////////////////////////////////////////////
  43. //    IPHLPAPI constants
  44. ////////////////////////////////////////////////////////////////////////////////
  45. const
  46.    IPHLPAPI_NAME           =  'iphlpapi.dll';
  47.   GETTCPTABLE_NAME         =  'GetTcpTable';
  48.   SETTCPENTRY_NAME        =  'SetTcpEntry';
  49.  
  50. const
  51.    MIB_TCP_STATE_DELETE_TCB= 12;
  52.  
  53. ////////////////////////////////////////////////////////////////////////////////
  54. //    NetBlock constants
  55. ////////////////////////////////////////////////////////////////////////////////
  56. const
  57.    NB_TABLE_SIZE     =  1024;
  58.  
  59. const
  60.   NB_BLOCK_NONE     =  0;
  61.    NB_BLOCK_INTERNET =  1;
  62.   NB_BLOCK_ALL      =  2;
  63.  
  64. ////////////////////////////////////////////////////////////////////////////////
  65. //    NetBlock data structures
  66. ////////////////////////////////////////////////////////////////////////////////
  67. type
  68.    PNetBlockInfo     =  ^TNetBlockInfo;
  69.   TNetBlockInfo     =  packed  record
  70.      dwBlockMode:   DWORD;
  71.      dwResolution:  DWORD;
  72.       dwTimer:       DWORD;
  73.   end;
  74.  
  75. ////////////////////////////////////////////////////////////////////////////////
  76. //    NetBlock functions
  77. ////////////////////////////////////////////////////////////////////////////////
  78. function    SetNetBlock(lpNetBlockInfo: PNetBlockInfo): DWORD;
  79. function    StatNetBlock(lpNetBlockInfo: PNetBlockInfo): DWORD;
  80. procedure   StopNetBlock;
  81.  
  82. var
  83.   x:       DWORD = 0;
  84.  
  85. implementation
  86.  
  87. ////////////////////////////////////////////////////////////////////////////////
  88. //    Protected variables
  89. ////////////////////////////////////////////////////////////////////////////////
  90. var
  91.    hIphlp:           HMODULE        =  0;
  92.   dwResolution:     DWORD           =  0;
  93.   dwBlockMode:      DWORD          =  0;
  94.   dwTimer:           DWORD          =  0;
  95.   dwProcError:      DWORD          =  0;
  96.    _GetTcpTable:     TGetTcpTable   =  nil;
  97.   _SetTcpEntry:      TSetTcpEntry   =  nil;
  98.  
  99. procedure NetBlockTimerProc(uTimerID,  uMessage: UINT; dwUser, dw1, dw2: DWORD); stdcall;
  100. var  lpTable:        PMIB_TCPTABLE;
  101.      lpRow:         PMIB_TCPROW;
  102.      bRemove:        Boolean;
  103.      dwReturn:      DWORD;
  104.      dwSize:         DWORD;
  105. begin
  106.  
  107.   Inc(x);
  108.  
  109.   // Start with an optimal  table size
  110.   dwSize:=(NB_TABLE_SIZE * SizeOf(MIB_TCPROW)) +  SizeOf(DWORD);
  111.  
  112.   // Allocate memory for the table
  113.    GetMem(lpTable, dwSize);
  114.  
  115.   // Get the table
  116.    dwReturn:=_GetTcpTable(lpTable, @dwSize, False);
  117.  
  118.   // We may  have to reallocate and try again
  119.   if (dwReturn =  ERROR_INSUFFICIENT_BUFFER) then
  120.   begin
  121.      // Reallocate  memory for new table
  122.      ReallocMem(lpTable, dwSize);
  123.      //  Make the call again
  124.      dwReturn:=_GetTcpTable(lpTable,  @dwSize, False);
  125.   end;
  126.  
  127.   // Check for succes
  128.   if  (dwReturn = ERROR_SUCCESS) then
  129.   begin
  130.      // Iterate the table
  131.       for dwSize:=0 to Pred(lpTable^.dwNumEntries) do
  132.      begin
  133.          // Get the row
  134.         lpRow:=@lpTable^.Table[dwSize];
  135.          // Check for 0.0.0.0 address
  136.         if (lpRow^.dwLocalAddr =  0) or (lpRow^.dwRemoteAddr = 0) then Continue;
  137.         // What  blocking mode are we in
  138.         case dwBlockMode of
  139.            //  Need to check the first two bytes in network address
  140.             NB_BLOCK_INTERNET :  bRemove:=not(Word(Pointer(@lpRow^.dwLocalAddr)^)  = Word(Pointer(@lpRow^.dwRemoteAddr)^));
  141.            //  Need to check all four bytes in network address
  142.             NB_BLOCK_ALL      :  bRemove:=not(lpRow^.dwLocalAddr =  lpRow^.dwRemoteAddr);
  143.         else
  144.            // No checking
  145.             bRemove:=False;
  146.         end;
  147.         // Do we need to  remove the entry?
  148.         if bRemove then
  149.         begin
  150.             // Set entry state
  151.            lpRow^.dwState:=MIB_TCP_STATE_DELETE_TCB;
  152.             // Remove the TCP entry
  153.            _SetTcpEntry(lpRow);
  154.          end;
  155.      end;
  156.   end;
  157.  
  158.   // Free the table
  159.    FreeMem(lpTable);
  160.  
  161. end;
  162.  
  163. function StatNetBlock(lpNetBlockInfo:  PNetBlockInfo): DWORD;
  164. begin
  165.  
  166.   // Parameter check
  167.   if  not(Assigned(lpNetBlockInfo)) then
  168.      // Null buffer
  169.       result:=ERROR_INVALID_PARAMETER
  170.   else
  171.   begin
  172.      //  Fill in the current settings
  173.      lpNetBlockInfo^.dwResolution:=dwResolution;
  174.       lpNetBlockInfo^.dwBlockMode:=dwBlockMode;
  175.       lpNetBlockInfo^.dwTimer:=dwTimer;
  176.      // Success
  177.       result:=ERROR_SUCCESS;
  178.   end;
  179.  
  180. end;
  181.  
  182. function  SetNetBlock(lpNetBlockInfo: PNetBlockInfo): DWORD;
  183. begin
  184.  
  185.    // Parameter check
  186.   if not(Assigned(lpNetBlockInfo)) then
  187.    begin
  188.      // Treat the same way as if StopNetBlock had been called
  189.       StopNetBlock;
  190.      // Success
  191.      result:=ERROR_SUCCESS;
  192.    end
  193.   else if (@_GetTcpTable = @_SetTcpEntry) then
  194.      // Failed  to load library or get the function pointers
  195.       result:=dwProcError
  196.   else if (lpNetBlockInfo^.dwResolution =  0) then
  197.      // Invalid time specified
  198.       result:=ERROR_INVALID_PARAMETER
  199.   else if  (lpNetBlockInfo^.dwBlockMode > NB_BLOCK_ALL) then
  200.      //  Invalid blocking mode
  201.      result:=ERROR_INVALID_PARAMETER
  202.    else
  203.   begin
  204.      // Kill the current timer if the blocking is  running
  205.      if (dwTimer > 0) then timeKillEvent(dwTimer);
  206.       // Clear timer tracking handle
  207.      dwTimer:=0;
  208.      // Save off  the current block mode and resolution
  209.      dwBlockMode:=lpNetBlockInfo^.dwBlockMode;
  210.       dwResolution:=lpNetBlockInfo^.dwResolution;
  211.      // If  the block mode is NB_BLOCK_NONE then nothing to do
  212.      if  (dwBlockMode = NB_BLOCK_NONE) then
  213.         // Success
  214.          result:=ERROR_SUCCESS
  215.      else
  216.      begin
  217.         // Create  the timer to handle the network blocking
  218.          dwTimer:=timeSetEvent(lpNetBlockInfo^.dwResolution, 0,  @NetBlockTimerProc, 0, TIME_PERIODIC or TIME_CALLBACK_FUNCTION);
  219.          // Check timer handle
  220.         if (dwTimer = 0) then
  221.             // Failure
  222.            result:=GetLastError
  223.         else
  224.             // Succes
  225.            result:=ERROR_SUCCESS;
  226.      end;
  227.    end;
  228.  
  229. end;
  230.  
  231. procedure StopNetBlock;
  232. begin
  233.  
  234.   //  This will stop the current net blocking
  235.   if (dwTimer > 0) then
  236.    begin
  237.      // Kill the timer
  238.      timeKillEvent(dwTimer);
  239.       // Reset all values
  240.      dwBlockMode:=NB_BLOCK_NONE;
  241.       dwResolution:=0;
  242.      dwTimer:=0;
  243.   end;
  244.  
  245. end;
  246.  
  247. initialization
  248.  
  249.    // Load the ip helper api library
  250.   hIphlp:=LoadLibrary(IPHLPAPI_NAME);
  251.  
  252.    // Attempt to get the function addresses
  253.   if (hIphlp > 0) then
  254.    begin
  255.  
  256.      @_GetTcpTable:=GetProcAddress(hIpHlp,  GETTCPTABLE_NAME);
  257.      if not(Assigned(@_GetTcpTable)) then
  258.          dwProcError:=GetLastError
  259.      else
  260.      begin
  261.          @_SetTcpEntry:=GetProcAddress(hIpHlp, SETTCPENTRY_NAME);
  262.          if not(Assigned(@_SetTcpEntry)) then dwProcError:=GetLastError
  263.       end;
  264.   end
  265.   else
  266.      // Save off the error
  267.       dwProcError:=GetLastError;
  268.  
  269. finalization
  270.  
  271.   // Kill  the timer if running
  272.   if (dwTimer > 0) then  timeKillEvent(dwTimer);
  273.  
  274.   // Clear functions
  275.    @_GetTcpTable:=nil;
  276.   @_SetTcpEntry:=nil;
  277.  
  278.   // Free the ip  helper api library
  279.   if (hIphlp > 0) then FreeLibrary(hIphlp);
  280.  
  281. end.
  282.  

it works perfect  :) :), but you have to "run it as administrator".
will there be some way to make it work without opening it as an administrator ??
« Last Edit: February 24, 2018, 02:27:09 pm by Ericktux »

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: how to disable internet access
« Reply #5 on: February 24, 2018, 02:55:10 pm »
Why do you need to disable internet access?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: how to disable internet access
« Reply #6 on: February 24, 2018, 03:20:28 pm »
if you have to ask that question then I hope you don't become a statistic.
 
It's a shame that such places like this turns into a place of devious miss deeds, because personally
if such code was needed for true control in an enclosed environment then it wouldn't be posted here.

 It's is like putting a gun in a baby's hand.

 This should of been taking up in a personal communication manner..

The only true wisdom is knowing you know nothing

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: how to disable internet access
« Reply #7 on: February 24, 2018, 03:38:38 pm »
Good friends, I am trying to develop a parental control software.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: how to disable internet access
« Reply #8 on: February 24, 2018, 03:45:37 pm »
ok, as being a parent I would think you should know not to just throw that stuff out there in the
public..

 Years ago I handed over some info to help one person out and I made  a mistake of doing it in a public
forum to later fine that info got turned into a wrecking machine, and it wasn't by the one that originally
was asking for the help, but by those that are just lurking for a poke.

 Please be advise, there aren't as many saints out there as you may think!
 :o
The only true wisdom is knowing you know nothing

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: how to disable internet access
« Reply #9 on: February 24, 2018, 03:58:39 pm »
Quote
it works perfect  :) :), but you have to "run it as administrator".
will there be some way to make it work without opening it as an administrator ??

I don't think such things are possible without root or admin rights.
I guess you need a GUI app to setup things and you need at least one service running to do the real job.  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018