Accueil > > > RÉCUPERER LE TYPE D'UN SERVEUR HTTP VIA WINSOCK
RÉCUPERER LE TYPE D'UN SERVEUR HTTP VIA WINSOCK
Information sur la source
Description
Un simple code pour recuperer le type d'un serveur http et le temps de reponse , et qui donc par la meme occasion montre comment jouer avec la reception de donnée spécifique par winsock. C'est simple, mais ca peut servir. Pour info, touts les serveurs ne renvoient pas toujours dans leurs headers leurs type, par exemple yahoo.fr , mais ce type d'exemple est rare (sur les quelques tests que j'ai fait) . Et sur votre form, il faut 3 textbox nommées "Host" , "srvtype" et "anstime" , un controle winsock nommé ws et un command button "command1" .
Source
- Private Declare Function GetTickCount Lib "kernel32" () As Long
- Dim answert As Long
- Dim hblisten As Boolean
- Dim buffer As String
-
- Private Sub Command1_Click()
- buffer = ""
- hblisten = True
- If Host.Text <> "" Then
- ws.Close
- ws.Connect "" & Host.Text & "", 80
- answert = GetTickCount
- Else
- MsgBox "Vous n'avez pas entré de serveur", vbCritical
- End If
- End Sub
-
-
- Private Sub ws_connect()
- If hblisten = True Then
- ws.SendData "GET http://" & Host.Text & "/ HTTP/1.0" & vbCrLf & _
- "Host: " & Host.Text & "" & vbCrLf & vbCrLf
- End If
- End Sub
-
- Private Sub ws_DataArrival(ByVal bytesTotal As Long)
- Dim data As String
- ws.GetData data
- buffer = buffer & data
- If hblisten = True Then
- If hb_str_in_str(buffer, "Server: ", vbCrLf) <> "" Then
- srvtype.Text = hb_str_in_str(buffer, "Server: ", vbCrLf)
- anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
- ws.Close
- hblisten = false
- Else
- srvtype.Text = "Can't get server type"
- anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
- ws.Close
- hblisten = false
- End If
-
- End If
- End Sub
-
- Public Function hb_str_in_str(source As String, stravant As String, strapres As String)
- If InStr(1, source, stravant) > 0 Then
- If InStr((InStr(1, source, stravant)), source, strapres) > 0 Then
- If Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant))) <> "" Then
- hb_str_in_str = Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant)))
- End If
- End If
- End If
- End Function
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim answert As Long
Dim hblisten As Boolean
Dim buffer As String
Private Sub Command1_Click()
buffer = ""
hblisten = True
If Host.Text <> "" Then
ws.Close
ws.Connect "" & Host.Text & "", 80
answert = GetTickCount
Else
MsgBox "Vous n'avez pas entré de serveur", vbCritical
End If
End Sub
Private Sub ws_connect()
If hblisten = True Then
ws.SendData "GET http://" & Host.Text & "/ HTTP/1.0" & vbCrLf & _
"Host: " & Host.Text & "" & vbCrLf & vbCrLf
End If
End Sub
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim data As String
ws.GetData data
buffer = buffer & data
If hblisten = True Then
If hb_str_in_str(buffer, "Server: ", vbCrLf) <> "" Then
srvtype.Text = hb_str_in_str(buffer, "Server: ", vbCrLf)
anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
ws.Close
hblisten = false
Else
srvtype.Text = "Can't get server type"
anstime.Text = "réponse du serveur en " & CDec((GetTickCount - answert) / 1000) & " secondes"
ws.Close
hblisten = false
End If
End If
End Sub
Public Function hb_str_in_str(source As String, stravant As String, strapres As String)
If InStr(1, source, stravant) > 0 Then
If InStr((InStr(1, source, stravant)), source, strapres) > 0 Then
If Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant))) <> "" Then
hb_str_in_str = Mid(source, (InStr(1, source, stravant) + Len(stravant)), InStr((InStr(1, source, stravant) + Len(stravant)), source, strapres) - (InStr(1, source, stravant) + Len(stravant)))
End If
End If
End If
End Function
Conclusion
en esperant que ca puisse servir
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
PRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGEPRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGE par richardc
http://www.c2idotnet.com/articles/presentation-des-api-rest-de-windows-azure-lister-les-comptes-de-storage
Désolé pour "toto", mais c2i existait avant blogs.developpeur.org et c'est mon site "officiel" ;-) ...
Cliquez pour lire la suite de l'article par richardc [HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] SLIDES ET DéMOS : AUTOUR DU W3C , NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Très bonne après-midi passée lors cette conférence avec le W3C, organisée par L' Inria sur les nouveaux standards, ce Mardi 14 Février, on sent vraiment que çà bosse au W3C, et l'avenir est très très prometteur pour le HTML5, notamment ...
Cliquez pour lire la suite de l'article par Gio GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|