SOCKS5-Proxy
Zum Code
Eigentlich als kompletter Artikel, kommt jetzt doch nur der Code. Es ist ein vollständiger SOCKS5-Server, hoffentlich fehlerlos ;-) Anbei ist gleich noch ein Beispiel, wie ein Client über einen solchen Proxy ins Internet kommt.

Das Besondere am SOCKS-Protokoll ist, dass der Proxy nicht mehr nur auf einen Port beschränkt ist, sondern der Client kann dem Proxy sagen, zu welchem Port sich der Proxy zum Zielrechner verbinden soll. Ich hab's getestet, also mein ICQ funktionierte über den Proxy.

Viel Spaß damit

History
02.01.2003 Online gestellt

Autor: Dominik Auras <Dominik_auf_vbinside.de>

Code aus IPs.bas
Option Explicit

Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long

Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal _
wVersionRequired&, lpWSAData As WinSocketDataType) As Long

Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long

Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal _
HostName$, ByVal HostLen%) As Long

Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal _
HostName$) As Long

Private Declare Function gethostbyaddr Lib "WSOCK32.DLL" (ByVal _
addr$, ByVal laenge%, ByVal typ%) As Long

Private Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, _
ByVal hpvSource&, ByVal cbCopy&)

Private Type HostDeType
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type

Const WS_VERSION_REQD = &H101
Const MIN_SOCKETS_REQD = 1
Const SOCKET_ERROR = -1
Const WSADescription_Len = 256
Const WSASYS_Status_Len = 128

Private Type WinSocketDataType
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type

Public Function GetIPs() As Variant
Dim IP As String, Host As String
Dim x As Integer, Liste() As String

Call InitSocketAPI
Host = MyHostName

ReDim Liste(0)
Do
IP = HostByName(Host, x)
If Len(IP) <> 0 Then
Liste(UBound(Liste)) = IP
ReDim Preserve Liste(UBound(Liste) + 1)
End If
x = x + 1
Loop While Len(IP) > 0

ReDim Preserve Liste(UBound(Liste) - 1)

Call CleanSockets

GetIPs = Liste
End Function

Private Sub InitSocketAPI()
Dim Result%
Dim LoBy%, HiBy%
Dim SocketData As WinSocketDataType

Result = WSAStartup(WS_VERSION_REQD, SocketData)
If Result <> 0 Then
MsgBox ("'winsock.dll' antwortet nicht !")
End
End If
End Sub

Private Function MyHostName() As String
Dim HostName As String * 256

If gethostname(HostName, 256) = SOCKET_ERROR Then
MsgBox "Windows Sockets error " & Str(WSAGetLastError())
Exit Function
Else
MyHostName = NextChar(Trim$(HostName), Chr$(0))
End If
End Function

Private Function HostByName(Name$, Optional x% = 0) As String
Dim MemIp() As Byte
Dim y%
Dim HostDeAddress&, HostIp&
Dim IpAddress$
Dim Host As HostDeType

HostDeAddress = gethostbyname(Name)
If HostDeAddress = 0 Then
HostByName = ""
Exit Function
End If

Call RtlMoveMemory(Host, HostDeAddress, LenB(Host))

For y = 0 To x
Call RtlMoveMemory(HostIp, Host.hAddrList + 4 * y, 4)
If HostIp = 0 Then
HostByName = ""
Exit Function
End If
Next y

ReDim MemIp(1 To Host.hLength)
Call RtlMoveMemory(MemIp(1), HostIp, Host.hLength)

IpAddress = ""

For y = 1 To Host.hLength
IpAddress = IpAddress & MemIp(y) & "."
Next y

IpAddress = Left$(IpAddress, Len(IpAddress) - 1)
HostByName = IpAddress
End Function

Private Sub CleanSockets()
Dim Result&

Result = WSACleanup()
If Result <> 0 Then
MsgBox ("Socket Error " & Trim$(Str$(Result)) & " in " & _
"Prozedur 'CleanSockets' aufgetreten !")
End
End If
End Sub

Private Function NextChar(Text$, Char$) As String
Dim pos%
pos = InStr(1, Text, Char)
If pos = 0 Then
NextChar = Text
Text = ""
Else
NextChar = Left$(Text, pos - 1)
Text = Mid$(Text, pos + Len(Char))
End If
End Function