Générateur ip

Description

Ce code permet de générer des adresses IP suivant le type de classe réseau (Classe A,B ou encore C).
Ce programme a été fait à partir d'un algo que l'on ma demandé de faire pour mon école...

Source / Exemple :


Public Nbpostes As Long
Public ClasseIp As String
Private Sub Command1_Click()
If TxtTypeReseau.Text <> "a" Then
    If TxtTypeReseau.Text <> "b" Then
        If TxtTypeReseau.Text <> "c" Then
            MsgBox "Type de réseau non reconnu", vbCritical + vbOKOnly
            TxtTypeReseau.Text = ""
            TxtNbMachine.Text = ""
        End If
    End If
End If
Nbpostes = CLng(TxtNbMachine.Text)
ClasseIp = TxtTypeReseau
VerifClasse Nbpostes, ClasseIp
End Sub
Private Sub VerifClasse(Nposts As Long, ClassIp As String)
Select Case ClassIp
    Case "a"
            If Nposts <= 16777214 And Nposts > 65534 Then
                MsgBox "Nombre de poste correct ", vbInformation + vbOKOnly
                CalcClasseA (Nposts)
            Else
                MsgBox "Nombre de poste incorrect!", vbCritical + vbOKOnly
            End If
    Case "b"
            If Nposts <= 65534 And Nposts > 254 Then
                MsgBox "Nombre de poste correct ", vbInformation + vbOKOnly
                CalcClasseB (Nposts)
            Else
                MsgBox "Nombre de poste incorrect!", vbCritical + vbOKOnly
            End If
    Case "c"
            If Nposts <= 254 And Nposts > 1 Then
                MsgBox "Nombre de poste correct ", vbInformation + vbOKOnly
                CalcClasseC (Nposts)
            Else
                MsgBox "Nombre de poste incorrect!", vbCritical + vbOKOnly
            End If
End Select
End Sub
Private Sub CalcClasseA(posts As Long)
Dim CalcIp1 As Integer
Dim CalcIp2 As Integer
Dim CalcIp3 As Integer
Dim ip As String
Dim ConteurPoste As Long
posts = Nbpostes
ref = InputBox("Entrez la première partie de l'adresse IP")
Do While ref < 1 Or ref > 126
    ref = InputBox("Entrez la première partie de l'adresse IP")
Loop
CalcIp3 = 0
CalcIp2 = 0
CalcIp1 = 0
ConteurPoste = 0
Do While CalcIp3 < 255 And posts > ConteurPoste
    If CalcIp2 >= 255 Then
    CalcIp3 = CalcIp3 + 1
    CalcIp2 = 0
    End If
    Do While CalcIp2 < 255 And posts > ConteurPoste
         If CalcIp1 >= 255 Then
         CalcIp2 = CalcIp2 + 1
         CalcIp1 = 0
         End If
         Do While CalcIp1 < 255 And posts > ConteurPoste
               CalcIp1 = CalcIp1 + 1
               ip = ref & "." & CalcIp3 & "." & CalcIp2 & "." & CalcIp1
               List1.AddItem ip
               ConteurPoste = ConteurPoste + 1
         Loop
    Loop
Loop
End Sub
Public Function CalcClasseB(posts As Long)
Dim CalcIp1 As Integer
Dim CalcIp2 As Integer
Dim ip As String
Dim ConteurPoste As Long
posts = Nbpostes
ref = InputBox("Entrez la première partie de l'adresse IP")
Do While ref < 128 Or ref > 191
    ref = InputBox("Entrez la première partie de l'adresse IP")
Loop
ref2 = InputBox("Entrez la deuxième partie de l'adresse IP")
Do While ref2 < 1 Or ref2 > 254
    ref2 = InputBox("Entrez la deuxième partie de l'adresse IP")
Loop
CalcIp2 = 0
CalcIp1 = 0
ConteurPoste = 0
    Do While CalcIp2 < 255 And posts > ConteurPoste
         If CalcIp1 >= 255 Then
         CalcIp2 = CalcIp2 + 1
         CalcIp1 = 0
         End If
         Do While CalcIp1 < 255 And posts > ConteurPoste
               CalcIp1 = CalcIp1 + 1
               ip = ref & "." & ref2 & "." & CalcIp2 & "." & CalcIp1
               List1.AddItem ip
               ConteurPoste = ConteurPoste + 1
         Loop
    Loop
End Function
Public Function CalcClasseC(posts As Long)
Dim CalcIp1 As Integer
Dim ip As String
Dim ConteurPoste As Long
posts = Nbpostes
ref = InputBox("Entrez la première partie de l'adresse IP")
Do While ref < 192 Or ref > 223
    ref = InputBox("Entrez la première partie de l'adresse IP")
Loop
ref1 = InputBox("Entrez la deuxième partie de l'adresse IP")
Do While ref1 < 0 Or ref1 > 255
    ref1 = InputBox("Entrez la deuxième partie de l'adresse IP")
Loop
ref2 = InputBox("Entrez la troisième partie de l'adresse IP")
Do While ref2 < 1 Or ref2 > 254
    ref2 = InputBox("Entrez la troisième partie de l'adresse IP")
Loop
CalcIp1 = 0
ConteurPoste = 0
         Do While CalcIp1 < 255 And posts > ConteurPoste
               CalcIp1 = CalcIp1 + 1
               ip = ref & "." & ref1 & "." & ref2 & "." & CalcIp1
               List1.AddItem ip
               ConteurPoste = ConteurPoste + 1
         Loop
End Function
Private Sub Command2_Click()
    End
End Sub

Conclusion :


Vous pouvez télécharger le ZIP....

Ps: j'ai modifié deux trois trucs qui posaient problème....

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.