I have the set of code writen in vb 2010 to reformat a text file of ip address and give me ipsec command to block the ipaddress to my server. It takes a long time when I'm doing 1000+ Ip Address to block a country. This might not be able to be fixed. It hangs the program tell its done. But still works good just take forerver.
Function Build() As String
Dim TextLine As String
Dim Display As String
Dim ipaddress As String
Dim subnet As String
Static p1 As String = ("netsh ipsec static add filter filterlist=")
Dim p2 As String = TextBox2.Text
Static P3 As String = (" srcaddr=")
Static p4 As String = (" srcmask=")
Static p5 As String = (" dstaddr=me description=")
Dim p6 As String = TextBox3.Text
Static p7 As String = (" protocol=any srcport=0 dstport=0")
Static n1 As String = ("#Run This Batch in Command Terimal For Windows 2003 Only")
Try
For Each TextLine In arraylist
' Dim tmp() As String = Split(TextLine)
Dim split As String() = TextLine.Split(New [Char]() {"/"})
ipaddress = split(0)
subnet = split(1)
If subnet.Contains("32") Then
subnet = subnet.Replace("32", "255.255.255.255")
ElseIf subnet.Contains("31") Then
subnet = subnet.Replace("31", "255.255.255.254")
ElseIf subnet.Contains("30") Then
subnet = subnet.Replace("30", "255.255.255.252")
ElseIf subnet.Contains("29") Then
subnet = subnet.Replace("29", "255.255.255.248")
ElseIf subnet.Contains("28") Then
subnet = subnet.Replace("28", "255.255.255.240")
ElseIf subnet.Contains("27") Then
subnet = subnet.Replace("27", "255.255.255.224")
ElseIf subnet.Contains("26") Then
subnet = subnet.Replace("26", "255.255.255.192")
ElseIf subnet.Contains("25") Then
subnet = subnet.Replace("25", "255.255.255.0")
ElseIf subnet.Contains("24") Then
subnet = subnet.Replace("24", "255.255.255.0")
ElseIf subnet.Contains("23") Then
subnet = subnet.Replace("23", "255.255.254.0")
ElseIf subnet.Contains("22") Then
subnet = subnet.Replace("22", "255.255.252.0")
ElseIf subnet.Contains("21") Then
subnet = subnet.Replace("21", "255.255.248.0")
ElseIf subnet.Contains("20") Then
subnet = subnet.Replace("20", "255.255.240.0")
ElseIf subnet.Contains("19") Then
subnet = subnet.Replace("19", "255.255.224.0")
ElseIf subnet.Contains("18") Then
subnet = subnet.Replace("18", "255.255.192.0")
ElseIf subnet.Contains("17") Then
subnet = subnet.Replace("17", "255.255.128.0")
ElseIf subnet.Contains("16") Then
subnet = subnet.Replace("16", "255.255.0.0")
ElseIf subnet.Contains("15") Then
subnet = subnet.Replace("15", "255.254.0.0")
ElseIf subnet.Contains("14") Then
subnet = subnet.Replace("14", "255.252.0.0")
ElseIf subnet.Contains("13") Then
subnet = subnet.Replace("13", "255.248.0.0")
ElseIf subnet.Contains("12") Then
subnet = subnet.Replace("12", "255.240.0.0")
ElseIf subnet.Contains("11") Then
subnet = subnet.Replace("11", "255.224.0.0")
ElseIf subnet.Contains("10") Then
subnet = subnet.Replace("10", "255.192.0.0")
ElseIf subnet.Contains("9") Then
subnet = subnet.Replace("9", "255.128.0.0")
ElseIf subnet.Contains("8") Then
subnet = subnet.Replace("8", "255.0.0.0")
End If
Display = Display & p1 & p2 & P3 & ipaddress & p4 & subnet & p5 & p6 & p7 & vbNewLine ' formats the data to my liking for viewing
TextBox1.Text = n1 & vbNewLine & Display ' puts data in text box
btn2003.Enabled = False
Next
arraylist.Clear()
arraylist.TrimToSize()
Catch ex As Exception
MessageBox.Show(ex.Message, "Invalid Format")
End Try
End Function