Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Winsock and Ips

Posted on 2003-11-27
6
Medium Priority
?
517 Views
Last Modified: 2013-11-13
I am creating a node based server, but only allowing the clients to connect to a central server.
Is there a way to ban or disallow certain ips i would put in  a .txt file?
0
Comment
Question by:raptorpb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:raptorpb1
ID: 9833796
btw, im editing aroud with this rogram
http://www.freevbcode.com/ShowCode.Asp?ID=2742
0
 
LVL 1

Expert Comment

by:thekng
ID: 9837406
try this:

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Dim bannedip As String
Open "C:\bannedips.txt" For Input As #1
While Not EOF(1)
Input #1, bannedip
If Winsock1.RemoteHost = bannedip Then Exit Sub
Wend
Close #1
End Sub
0
 

Author Comment

by:raptorpb1
ID: 9840981
Do you think if I replaced the C:\bannedips.txt and pu http://www.mysite.com/bannedips.txt it would work?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:raptorpb1
ID: 9841861
How can I make it so that it sends the user a message before it disconnects him?
txtoutput = "You have been banned"
0
 
LVL 1

Expert Comment

by:thekng
ID: 9842849
ok for the URL you'll need to create another winsock:

Public m_strRemoteHost
Public m_strFilePath
Public m_strHttpResponse
Public m_bResponseReceived

Public Function BannedIps()
Dim strURL As String
strURL = "www.mysite.com/bannedips.txt" 'Change to the real URL (without http://)
m_strRemoteHost = Left$(strURL, InStr(1, strURL, "/") - 1)
m_strFilePath = Mid$(strURL, InStr(1, strURL, "/"))
m_strHttpResponse = ""
m_bResponseReceived = False
    With Form1.Winsock1
        .Close
        .LocalPort = 0
        .Connect m_strRemoteHost, 80
    End With
End Function


Private Sub Form_Load()
BannedIps
End Sub

Private Sub Winsock2_Connect()
    Dim strHttpRequest As String
    strHttpRequest = "GET " & m_strFilePath & " HTTP/1.1" & vbCrLf
    strHttpRequest = strHttpRequest & "Host: " & m_strRemoteHost & vbCrLf
    strHttpRequest = strHttpRequest & "Connection: close" & vbCrLf
    strHttpRequest = strHttpRequest & "Accept: */*" & vbCrLf
    strHttpRequest = strHttpRequest & vbCrLf
    Winsock2.SendData strHttpRequest
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
    On Error Resume Next
    Dim strData As String
    Winsock2.GetData strData
    m_strHttpResponse = m_strHttpResponse & strData
    Open "C:\bannedips.txt" For Append As #1
    Print #1, Mid(m_strHttpResponse, _
                            InStr(1, m_strHttpResponse, _
                            vbCrLf & vbCrLf) + 4)
    Close #1
End Sub

and then

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Dim bannedip As String
Open "C:\bannedips.txt" For Input As #1
While Not EOF(1)
Input #1, bannedip
If Winsock1.RemoteHost = bannedip Then Exit Sub
Wend
Close #1
End Sub

will open the updated C:\bannedips.txt"

and for the "You have been banned" message:
in the client app also check www.mysite.com/bannedips.txt if connection is not accepted.
0
 
LVL 1

Accepted Solution

by:
thekng earned 2000 total points
ID: 9845158
You can also use the Internet Transfer Control 6.0 (add it from Project->Components) and then:

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Dim bannedip As String
Dim bannedipstxt As String
Dim i As Integer
bannedipstxt = Inet1.OpenURL("www.mysite.com/bannedips.txt")
For i = 0 To UBound(Split(bannedipstxt, vbLf))
bannedip = Split(bannedipstxt, vbCrLf)(i)
If Winsock1.RemoteHost = bannedip Then Exit Sub
Next
End Sub

much shorter :P
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question