pour mon boulot, j'ai eu à faire faire des tests réseau à des personnes qui se connectaient chez nous (traceroute et ping)
Pour éviter de leur faire faire des manipulations "compliquées", j'ai fait un petit programme PB qui lance un ping et un tracert, récupère le résultat, l'enregistre dans un fichier texte et envoie le tout par mail.
NB : le prog utilise les libs de Gnozal Pureresize et PureSMTP (pour une raison que j'ignore encore, l'envoi de mail par les commandes natives PB ne fonctionne pas avec le serveur mail du boulot), ainsi que Purecolor, toujours de Gnozal.
J'ai fait ça à l'arrache, ça n'est certainement pas très académique, mais ça a le mérite de fonctionner
Naturellement , toute remarque est la bienvenue
Code : Tout sélectionner
;{- Enumerations / DataSections
;{ Windows
Enumeration
#window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Panel_2
#Text_infos
#Text_27
#Text_23
#Text_21
#String_port
#Text_20
#Text_19
#Text_17
#Text_16
#Text_activite
#Text_3
#Button_4
#Frame3D_5
#Frame3D_7
#Frame3D_8
#IPAddress_1
#CheckBox_tracert_1
#IPAddress_2
#CheckBox_tracert_2
#String_serveur
#String_user
#String_pass
#Text_26
#string_destinataires
EndEnumeration
;}
;{ Fonts
Enumeration
#Font_Panel_2
#Font_Text_infos
#Font_Text_27
#Font_Text_23
#Font_Text_21
#Font_String_port
#Font_Text_20
#Font_Text_19
#Font_Text_17
#Font_Text_16
#Font_Text_activite
#Font_Text_3
#Font_Button_4
#Font_Frame3D_5
#Font_Frame3D_7
#Font_Frame3D_8
#Font_IPAddress_1
#Font_CheckBox_tracert_1
#Font_IPAddress_2
#Font_CheckBox_tracert_2
#Font_String_pass
#Font_Text_26
#Font_string_destinataires
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#window_0, 550, 339, 449, 343, "Test réseau Ping / Tracert", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
PanelGadget(#Panel_2, 20, 20, 410, 310)
; Tests
AddGadgetItem(#Panel_2, -1, "Tests")
TextGadget(#Text_infos, 15, 140, 370, 15, "", #PB_Text_Center)
TextGadget(#Text_activite, 55, 235, 295, 20, "", #PB_Text_Center)
TextGadget(#Text_3, 15, 10, 370, 125, "Ce programme est destiné à lancer une série de tests réseau vers les serveurs Portal. Les résultats sont normalement envoyés automatiquement par mail sans manipulation particulière. En cas d'échec de l'envoi, les résultats sont sauvegardés dans un fichier que nous récupèrerons.", #PB_Text_Border|#PB_Text_Center)
ButtonGadget(#Button_4, 100, 175, 205, 25, "Lancer le test")
Frame3DGadget(#Frame3D_5, 45, 215, 315, 45, "Activité")
; Paramètres
AddGadgetItem(#Panel_2, -1, "Paramètres")
TextGadget(#Text_27, 25, 235, 75, 20, "séparés par des ';'", #PB_Text_Center)
TextGadget(#Text_23, 200, 182, 75, 20, "Mot de passe :", #PB_Text_Right)
TextGadget(#Text_21, 60, 182, 40, 20, "User :", #PB_Text_Right)
StringGadget(#String_port, 330, 150, 35, 20, "", #PB_String_Numeric)
TextGadget(#Text_20, 35, 82, 85, 20, "Portal 1 :", #PB_Text_Right)
TextGadget(#Text_19, 35, 47, 85, 20, "Portal 2 :", #PB_Text_Right)
TextGadget(#Text_17, 280, 152, 45, 20, "Port :", #PB_Text_Right)
TextGadget(#Text_16, 40, 152, 60, 20, "Serveur :", #PB_Text_Right)
Frame3DGadget(#Frame3D_7, 20, 20, 365, 100, "Adresses")
Frame3DGadget(#Frame3D_8, 20, 130, 365, 140, "SMTP")
IPAddressGadget(#IPAddress_1, 130, 45, 140, 20)
CheckBoxGadget(#CheckBox_tracert_1, 295, 45, 60, 20, "Tracert")
IPAddressGadget(#IPAddress_2, 130, 80, 140, 20)
CheckBoxGadget(#CheckBox_tracert_2, 295, 80, 55, 20, "Tracert")
StringGadget(#String_serveur, 105, 150, 140, 20, "")
StringGadget(#String_user, 105, 180, 90, 20, "")
StringGadget(#String_pass, 280, 180, 85, 20, "")
TextGadget(#Text_26, 30, 215, 70, 20, "Destinataires :")
EditorGadget(#string_destinataires, 105, 210, 260, 50)
CloseGadgetList()
; Gadget Resizing
PureRESIZE_SetGadgetResize(#Panel_2, 1, 1, 1, 1)
PureRESIZE_SetGadgetResize(#Text_infos, 1, 1, 1, 0)
PureRESIZE_SetGadgetResize(#Text_27, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#Text_23, 0, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Text_21, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#String_port, 0, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Text_17, 0, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Text_16, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#Text_activite, 1, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Text_3, 1, 1, 1, 0)
PureRESIZE_SetGadgetResize(#Button_4, 0, 0, 0, 1, #Panel_2)
PureRESIZE_CenterGadget(#Button_4, 1, 0)
PureRESIZE_SetGadgetResize(#Frame3D_5, 1, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Frame3D_7, 1, 1, 1, 0)
PureRESIZE_SetGadgetResize(#Frame3D_8, 1, 0, 1, 1)
PureRESIZE_SetGadgetResize(#CheckBox_tracert_1, 0, 1, 1, 0)
PureRESIZE_SetGadgetResize(#CheckBox_tracert_2, 0, 1, 1, 0)
PureRESIZE_SetGadgetResize(#String_serveur, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#String_user, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#String_pass, 0, 0, 1, 1)
PureRESIZE_SetGadgetResize(#Text_26, 1, 0, 0, 1)
PureRESIZE_SetGadgetResize(#string_destinataires, 1, 0, 1, 1)
; Gadget Fonts
SetGadgetFont(#Panel_2, LoadFont(#Font_Panel_2, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_infos, LoadFont(#Font_Text_infos, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_27, LoadFont(#Font_Text_27, "Tahoma", 7, #PB_Font_HighQuality))
SetGadgetFont(#Text_23, LoadFont(#Font_Text_23, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_21, LoadFont(#Font_Text_21, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#String_port, LoadFont(#Font_String_port, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_20, LoadFont(#Font_Text_20, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_19, LoadFont(#Font_Text_19, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_17, LoadFont(#Font_Text_17, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_16, LoadFont(#Font_Text_16, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_activite, LoadFont(#Font_Text_activite, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_3, LoadFont(#Font_Text_3, "Tahoma", 11, #PB_Font_HighQuality))
SetGadgetFont(#Button_4, LoadFont(#Font_Button_4, "Tahoma", 9, #PB_Font_HighQuality))
SetGadgetFont(#Frame3D_5, LoadFont(#Font_Frame3D_5, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Frame3D_7, LoadFont(#Font_Frame3D_7, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Frame3D_8, LoadFont(#Font_Frame3D_8, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#IPAddress_1, LoadFont(#Font_IPAddress_1, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#CheckBox_tracert_1, LoadFont(#Font_CheckBox_tracert_1, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#IPAddress_2, LoadFont(#Font_IPAddress_2, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#CheckBox_tracert_2, LoadFont(#Font_CheckBox_tracert_2, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#String_pass, LoadFont(#Font_String_pass, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#Text_26, LoadFont(#Font_Text_26, "Tahoma", 8, #PB_Font_HighQuality))
SetGadgetFont(#string_destinataires, LoadFont(#Font_string_destinataires, "Tahoma", 8, #PB_Font_HighQuality))
; Gadget Colors
PureCOLOR_SetGadgetColor(#Text_infos, $FF0000, #PureCOLOR_DontSetBackColor)
PureCOLOR_SetGadgetColor(#String_port, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#Text_activite, $8080FF, #PureCOLOR_DontSetBackColor)
PureCOLOR_SetGadgetColor(#Text_3, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#IPAddress_1, #PureCOLOR_SystemColor, $80FFFF)
PureCOLOR_SetGadgetColor(#IPAddress_2, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#String_serveur, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#String_user, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#String_pass, #PureCOLOR_SystemColor, $B4FCF9)
PureCOLOR_SetGadgetColor(#string_destinataires, #PureCOLOR_SystemColor, $FFFFFF)
; Window Minimum Size
PureRESIZE_SetWindowMinimumSize(#window_0, 449, 343)
EndIf
EndProcedure
Procedure.s ping(ip$)
SetGadgetText(#Text_activite,"Ping vers "+ip$)
ping = RunProgram("ping",ip$,"",#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
sortie$ = ""
If ping
While ProgramRunning(ping)
If AvailableProgramOutput(ping)
sortie$ + ReadProgramString(ping) + #crlf$
EndIf
Wend
;MessageRequester("Stop",sortie$)
CloseProgram(ping)
EndIf
SetGadgetText(#Text_activite," ")
ProcedureReturn sortie$
EndProcedure
Procedure.s tracert(ip$)
SetGadgetText(#Text_activite,"Traceroute vers "+ip$)
tracert = RunProgram("tracert",ip$,"",#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
sortie$ = ""
If tracert
While ProgramRunning(tracert)
If AvailableProgramOutput(tracert)
sortie$ + ReadProgramString(tracert) + #crlf$
;OemToChar_(sortie$,sortie$)
;sortie$ + Chr(10)+Chr(13)
EndIf
Wend
CloseProgram(tracert)
EndIf
SetGadgetText(#Text_activite," ")
ProcedureReturn sortie$
EndProcedure
Procedure.b envoi_mail(message$)
PureSMTP_SkipInitNetwork(0)
SetGadgetText(#Text_activite,"Envoi des résultats par mail")
MySMTPServer.s = GetGadgetText(#String_serveur)
MySMTPPort.l = Val(GetGadgetText(#String_port))
If PureSMTP_OpenSMTPConnection(MySMTPServer, MySMTPPort) = #PureSMTP_Ok
Debug PureSMTP_GetLastServerMessage()
MailTo.s = GetGadgetText(#string_destinataires)
MailFrom.s = "test@test.com" ; mettre l'adresse de l'émetteur
ExamineIPAddresses()
ip = NextIPAddress()
Subject.s = "Résultat de Ping / Tracert - Envoi depuis "+Hostname()+" ("+IPString(ip)+")"
MsgBody.s = message$
Attachments.s = ""
Username.s = GetGadgetText(#String_user)
Password.s = GetGadgetText(#String_pass)
Status.l = PureSMTP_SendMail(MailTo, MailFrom, Subject, MsgBody, Attachments, Username, Password)
If Status = #PureSMTP_Ok
sent = #true
Else
sent = #False
EndIf
PureSMTP_CloseSMTPConnection()
Else
sent = #False
EndIf
SetGadgetText(#Text_activite," ")
ProcedureReturn sent
EndProcedure
Procedure save_fichier(res$)
fic$ = GetTemporaryDirectory()+"test_reseau.txt"
If CreateFile(0,fic$)
WriteStringN(0,res$)
CloseFile(0)
EndIf
EndProcedure
Procedure lancer_test()
result$ = ping(GetGadgetText(#IPAddress_1))
If GetGadgetState(#CheckBox_tracert_1) = #pb_checkbox_checked
result$ + tracert(GetGadgetText(#IPAddress_1))
EndIf
result$+#crlf$+#crlf$+ping(GetGadgetText(#IPAddress_2))+#crlf$+#crlf$
If GetGadgetState(#CheckBox_tracert_2) = #pb_checkbox_checked
result$ + tracert(GetGadgetText(#IPAddress_2))
EndIf
OemToChar_(result$,result$)
save_fichier(result$)
;MessageRequester("info",result$)
If envoi_mail(result$)
MessageRequester("Information","Le résultat du test a correctement été envoyé.")
Else
r = MessageRequester("Erreur","Un problème est survenu dans l'envoi du fichier."+Chr(10)+"Voulez-vous ouvrir le fichier résultat du test ?",#PB_MessageRequester_YesNo)
If r = #PB_MessageRequester_Yes
RunProgram("notepad",GetTemporaryDirectory()+"test_reseau.txt","")
EndIf
EndIf
EndProcedure
Procedure initialisations()
SetGadgetText(#String_serveur,"") ; mettre l'adresse du serveur de messagerie
SetGadgetText(#String_port,"25")
SetGadgetState(#IPAddress_1,MakeIPAddress(192,168,1,1)) ; adresse IP à tester
SetGadgetState(#IPAddress_2,MakeIPAddress(192,168,1,2)) ; adresse IP à tester
SetGadgetState(#CheckBox_tracert_2,1)
SetGadgetText(#string_destinataires,"toto@toto.com;titi@titi.com") ; mettre les adresse mail des destinataires, séparées par des ";"
SetGadgetText(#Text_activite,"En attente")
InitNetwork()
ExamineIPAddresses()
ip = NextIPAddress()
SetGadgetText(#Text_infos,Hostname()+" - "+IPString(ip))
EndProcedure
OpenWindow_Window_0()
initialisations()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Button_4
lancer_test()
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #window_0
CloseWindow(#window_0)
Break
EndIf
EndSelect
ForEver
;
;}