I need to block (not just close but BLOCK them) a range of ports on a computer
1. can I do it from VB ?
2. If yes , than how :-)
3. How many ports are there above 1024 ???
thnxs
Printable View
I need to block (not just close but BLOCK them) a range of ports on a computer
1. can I do it from VB ?
2. If yes , than how :-)
3. How many ports are there above 1024 ???
thnxs
What do you mean BLOCK??? Juz refer to your previous thread
When I say "ports" I mean like the ones the a web server is using (80), or the one that an email is using (25) .... or ICQ ... or what ever ...
the story:
My little brother is playing an online game, the problem is that he plays it ALL the time (about 18 hours a day), and my mother asked me to build a program that will let him play only on certain hours, so I was thinking if I can block the PORT that the game is using during certain hours, than he won't be able to play (the program will run in the background all the time, openning the ports on certain hours, and blocking them all the rest of the time ..).
the problem is that I have checked and this game opens a random port between 1024 .. to whatever, so I need to block all of them.
I do not think that your idea is do-able, but you can do something else, like check if the game is runing then close the whole game, this may work.
the game is not running in a window, so I don't know how to get the handle of it ...
The simple way to block your bros from play the games is blocking the URL instead of port like what WinGate/FireWall was did. because the is damn difficult to verified the port number that the games is using (1 to 32,767 available port). Unless you're such free till nothing to do, then you can go ahead and that may call it as a hacker mission :)
To block a URL is much much more easy then the port number. try to get more information for the inet control in Visual Basic or lOOk depth into the API function, sure you can do it.
cheers!
Chris.C
The program doesn't really use a URL, the game is EverQuest, and its using an arbitrary port >1024 each time it starts (that's I know from their tech page), if I would be able to find the window handle (it is not running in a window mode though so I don't know how to find it without the window caption), than I will be able to shut the program off (send the handle a close command or what ever), but I need to know how to do that ...
Maybe there is a way to block IP addresses, I know the IP's of the servers it is using.
by the way, he is running win98 ...
To find a window without caption is easy, but you need to know the Window Class that the EverQuest is using.
or you can just pass a zero in the lpClassname arguement, and it will find all the Window regardless to thier class type. But to do this you need to change the lpClassName from String to Long in the FindWindow APi function.
Code:Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060&
Private EverQuest_HWND as Long
Private Sub Command1_Click
EverQuest_HWND = FindWindow(0&, vbNullString)
'If return handle is not zero, then juz close the program.
If EverQuest_HWND <> 0 Then SendMessage EverQuest_HWND, WM_SYSCOMMAND, SC_CLOSE, 0&
End Sub
You also can get the respective window class base on thier current window location:
Assume the EverQuest game is running with Maximized window screen.
But I'm not sure this will work or not, because I've not try it out yet.
[Edited by Chris on 06-25-2000 at 08:58 PM]Code:Option Explicit
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060&
Private xReturn As String
Private Command1_Click()
'GetWindows Handle
EverQuest_HWND = WindowFromPoint(0, 0)
If EverQuest_HWND <> 0 Then
xReturn = String(255, Chr(0))
If GetClassName(EverQuest_HWND, xReturn, Len(xReturn)) <> 0 Then
EverQuest_CLASS = Left(xReturn, InStr(1, xReturn, Chr(0), vbBinaryCompare) - 1)
If EverQuest_CLASS <> "" Then
EverQuest_HWND = FindWindow(0&, EverQuest_CLASS)
SendMessage EverQuest_HWND, WM_SYSCOMMAND, SC_CLOSE, 0&
End If
End If
End If
You might want to build something that changes the name of the game executable instead, or simply deletes it, then you have a copy of it build in your program which would rewrite it at ceratin times, or just change name :)
Thanks guys, I will try it as soon as I can (today), and I will post the results.
I liked the Idea with renaming and saving a copy of the file name, but the problem is that my brother is a pretty smart guy when he wants to ... and he really likes this game, so I will try both ways and see which works better :-)
Thnxs, and if you have any more ideas how to "solve" the problem, please post it.
Depends on the game too, maybe I know something about it...
What is the game?
EverQuest
http://www.EverQuest.com
(pretty cool game actually but 18 hours a day ???).
:-)
Is the game windows or DOS-based?
I think it's windows based as almost all new games are :)
So, a windows game requeries DLL's and registry keys.. ;)
Getting my point?
Here's where the keys often lies
HKCU\Software\EverQuest or something
(HKLM)
You might want to change something like Installed = Yes to No so the game wont start then just change it back or something.. or hit away any dll's or devices the game uses... i'm sure you can come up with many ideas... good luck
By the way, I will also need to disable his CTRL-ALT-DEL
so he won't be able to force the system to kill the program, anyone know of a better way than that / how to disable the CTRL-ALT-DEL ?
yes, that's a good one Rodik, I might be able to rename a DLL in the system folder, and that's it, just need to find a DLL that is Important for the game, but than I still need to shut the game off after lets say 2 hours or so ...
You can use this code snippet and it even wont show up in the Ctrl+Alt+Del list... hehe, he can try to shut it down now... ;)
It's almost selfexplainatory so I guess you can use this :)Code:'Declarations
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0
'Code:
'To remove your program from the Ctrl+Alt+Delete list, call the MakeMeService procedure:
Public Sub RemoveProgramFromList()
Dim lngProcessID As Long
Dim lngReturn As Long
lngProcessID = GetCurrentProcessId()
lngReturn = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub
'To restore your application to the Ctrl+Alt+Delete list, call the UnMakeMeService procedure:
Public Sub AddProgramToList()
Dim lngProcessID As Long
Dim lngReturn As Long
lngProcessID = GetCurrentProcessId()
lngReturn = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub
GL
Rodik's code is only hide your progrom from the Task Manager, but you still can call the Task Manager but pressing the Ctrl+Atl+Del key.
If you want to disable the Ctrl+Atl+Del key, you need to this way Tip 33
Wow !!!
Guys, you don't know how much you helped me with that ...
I was sitting until 5am trying to think of good ways to do it.
I even went all the way to use magic folders, and enable and disbable the folder from withing my program by sending key strokes to magic folder (password and stuff), but your Ideas are much better than that :-)
Thanks, and if you have more information, please post it !
I really appriciate it.
Yeah Chris, you're right! My code doesn't disable Ctrl+Alt+Del which I explained but it makes a service out of his prorgam. So it doesn't matter if he can get to the taskbar cause he can't shut the program down anyway... :)
I mean, if he wants, he just pushes the power button and then restarts and poof! But whatever....
Hey, Asabi, juz bare in mind that both the hide from the Task Manager list and Disable the Ctrl+Atl+Del key will not be work under WinNT platform.
But he is using win98
And the game wouldn't work under NT anyway ... :-)
Than everything should be find & under you prediction. lol
Hope you can make it.
Cheers!
Yep, Everything should be fine :-)
I will probably even write some code to check the time and date with NASA or my home machine (through an ASP page)something to make sure he doesn't try to cheat the program with dates/times .. :-)
Thanks again, I will post the results.
Hi Asabi,
You said you can check the date time with NASA, can you tell me you you do it? because I'm interested too.
Cheers!
Well,
I understood from a friend that they have it somewhere on their website, if they do, than I can use the internet control to retrieve the HTML code of the page, strip out most of it, and get just the current time and date :-)
And if that doesn't work, than I can do the same with my machine.
having an ASP page that would just show the Date and Time on my home machine.
Than from withing the VB program send a URL request to my home machine, and retrieve that information.
When it is done, I will post the code here.
Cheers.
Actually, NASA hasn't anything to do with this (although, they were the first to start with it). The thing is called time server, which is a 'TimeD' running on a Unix machines. Most of them come with it and the format is simple.
You just connect with a winsock control the time-port which is 37 and you get a three charachter long garbage then it disconnects. So, I don't know what to do with this three character long string, but there is some way to decrypt it. It's supposed to be fast since even the milliseconds are sent.
The two most used protocols are Network Time Protocol (Internet RFC-1305a) and Simple Network Time Protocol (SNTP).
I don't know how the client works because I've never used it before.
If you want to know more, here are some links.
A type of search you could do
Time Servers