This is a good one but its a in console but i hope you will like it and it has not alot code . the program works like when you enter a IP address and press enter key in your keyboard then you will see the class of the ip address and subnet mask and IP binary and network address and at last broadcast address so i hope you will like the features and dont forget you can also make alot features for this if you made anything dont forget to comment it ok lets begin making it now make a console project and name it and when it loading successful then add this code down
Imports System.Net
Module Module1
'Author : Mohamed Shimran
'Blog : http://www.ultimateprogrammingtutorials.blogspot.com
Sub Main()
Console.Write("Insert IP Address : ")
Dim IP As String = Console.ReadLine
Console.WriteLine("")
Dim IP_Array() As String = IP.Split(".")
Dim First_Byte As Integer = IP_Array(0)
Dim Bit_First_Byte As String = Convert.ToString(First_Byte, 2)
Dim Bit_First_Byte_Padded As String = Bit_First_Byte.PadLeft(8, "0")
If Bit_First_Byte_Padded.Substring(0, 1) = "0" Then
class_X(IP_Array, "A", "11111111.00000000.00000000.00000000", "00000000.11111111.11111111.11111111")
ElseIf Bit_First_Byte_Padded.Substring(0, 2) = "10" Then
class_X(IP_Array, "B", "11111111.11111111.00000000.00000000", "00000000.00000000.11111111.11111111")
ElseIf Bit_First_Byte_Padded.Substring(0, 2) = "11" Then
class_X(IP_Array, "C", "11111111.11111111.11111111.00000000", "00000000.00000000.00000000.11111111")
End If
Console.ReadKey()
End Sub
Sub class_X(ByVal IP() As String, ByVal Classe As String, ByVal SubMask As String, ByVal SubMaskInv As String)
Console.WriteLine("******************************************************")
Console.WriteLine("Class: " & Classe)
Console.WriteLine("")
If Classe = "A" Then
Console.WriteLine("Subnet Mask: 255.0.0.0")
ElseIf Classe = "B" Then
Console.WriteLine("Subnet Mask: 255.255.0.0")
ElseIf Classe = "C" Then
Console.WriteLine("Subnet Mask: 255.255.255.0")
End If
Console.WriteLine("")
Dim Binary_IP As String = ""
For i = 0 To IP.Length - 1
Dim Byte_ As Integer = IP(i)
Dim Bit As String = Convert.ToString(Byte_, 2)
Dim Bit_Padded As String = Bit.PadLeft(8, "0")
If Not i = IP.Length - 1 Then
Binary_IP += Bit_Padded & "."
Else
Binary_IP += Bit_Padded
End If
Next
Console.WriteLine("IP Binary: " & Binary_IP)
Console.WriteLine("")
Dim Subnet_Mask_Binary As String = SubMask
Dim Mask_Array() As Char = Subnet_Mask_Binary.ToCharArray
Dim IP_Array() As Char = Binary_IP.ToCharArray
Dim Network_Address_Binary As String = ""
For i = 0 To Mask_Array.Length - 1
If IP_Array(i) = "1" And Mask_Array(i) = "1" Then
Network_Address_Binary += "1"
ElseIf IP_Array(i) = "." Then
Network_Address_Binary += "."
Else
Network_Address_Binary += "0"
End If
Next
Dim Network_Address As String = ""
Dim Network_Array() As String = Network_Address_Binary.Split(".")
For i = 0 To Network_Array.Length - 1
Network_Address += Bin_To_Dec(Network_Array(i)) & "."
Next
Console.WriteLine("Network Address: " & Network_Address.Substring(0, Network_Address.Length - 1))
Console.WriteLine("")
Dim Subnet_Mask_Inverted As String = SubMaskInv
Dim Mask_Inverted_Array() As Char = Subnet_Mask_Inverted.ToCharArray
Dim Broadcast_Address_Binary As String = ""
For i = 0 To Mask_Inverted_Array.Length - 1
If IP_Array(i) = "0" And Mask_Inverted_Array(i) = "0" Then
Broadcast_Address_Binary += "0"
ElseIf IP_Array(i) = "." Then
Broadcast_Address_Binary += "."
Else
Broadcast_Address_Binary += "1"
End If
Next
Dim Broadcast_Address As String = ""
Dim Broadcast_Array() As String = Broadcast_Address_Binary.Split(".")
For i = 0 To Broadcast_Array.Length - 1
Broadcast_Address += Bin_To_Dec(Broadcast_Array(i)) & "."
Next
Console.WriteLine("Broadcast Address: " & Broadcast_Address.Substring(0, Broadcast_Address.Length - 1))
Console.WriteLine("******************************************************")
End Sub
Public Function Bin_To_Dec(ByVal Bin As String)
Dim dec As Double = Nothing
Dim length As Integer = Len(Bin)
Dim temp As Integer = Nothing
Dim x As Integer = Nothing
For x = 1 To length
temp = Val(Mid(Bin, length, 1))
length = length - 1
If temp <> "0" Then
dec += (2 ^ (x - 1))
End If
Next
Return dec
End Function
End Module
now debug and try it

1 comments:
This code does not calculate the netmask, you only check the first Octet of the IP's Binary and then determine the class segment which okay. But When you print the NetMask you do not follow the CIDR pattern. You statically assign the NetMask which is not okay.
ReplyPost a Comment
Note: Only a member of this blog may post a comment.