Leeus Posted December 12, 2003 Posted December 12, 2003 Has anyone got a function to add a number to an ip address? I want it to cope with once it reaches 254 to increment the previous octet also?!? Quote
HJB417 Posted December 12, 2003 Posted December 12, 2003 you would need to use neested loops. I would use nested foor loops. I'll post code later though. Quote
Grimfort Posted December 12, 2003 Posted December 12, 2003 (edited) This is soooo going to be used for a hack attack :) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strNext As String = "0.0.0.0" Dim intIndex As Integer For intIndex = 0 To 100000 Debug.WriteLine(strNext) strNext = funcNextIPAddy(strNext) Next End Sub Private Function funcNextIPAddy(ByVal strIPAddy) As String Dim intIndex As Integer Dim intRev As Integer Dim strSplit() As String = Split(strIPAddy, ".") Dim bytIP(3) As Byte 'Just to make sure it works ReDim Preserve strSplit(3) Dim bAdded As Boolean = False For intIndex = 3 To 0 Step -1 bytIP(intIndex) = funcFixByte(strSplit(intIndex)) If bAdded = False Then If bytIP(intIndex) < 255 Then bytIP(intIndex) += 1 bAdded = True For intRev = intIndex + 1 To 3 bytIP(intRev) = 0 Next End If End If Next Return CStr(bytIP(0)) & "." & CStr(bytIP(1)) & "." & CStr(bytIP(2)) & "." & CStr(bytIP(3)) End Function Private Function funcFixByte(ByVal Data As String) As Byte Dim intVal As Integer = Val(Data) If intVal < 0 Then intVal = 0 If intVal > 255 Then intVal = 255 Return CByte(intVal) End Function Edited November 27, 2005 by PlausiblyDamp Quote
Leeus Posted December 12, 2003 Author Posted December 12, 2003 Thanks, not quite for hacking but preventing it! ;) Quote
HJB417 Posted December 12, 2003 Posted December 12, 2003 (edited) you're gonna need to modify to reduce the # of ips produced. string[] GenerateIps() { ArrayList ips = new ArrayList(); string a=null,b=null,c=null,d=null; for(int intA = 1; intA < 255; intA++) { a = intA.ToString(); for(int intB = 0; intB < 255; intB++) { b = intB.ToString(); for(int intC = 0; intC < 255; intC++) { c = intC.ToString(); for(int intD = 0; intD < 255; intD++) { d = intD.ToString(); ips.Add(a + "." + b + "." + c + "." + d); } ips.Add(a + "." + b + "." + c + "." + d); } ips.Add(a + "." + b + "." + c + "." + d); } ips.Add(a + "." + b + "." + c + "." + d); } return (string[]) ips.ToArray(typeof(string)); } This is soooo going to be used for a hack attack :) More like, try to use. Anyway, if someone trying to hack and is asking a question like this, I highly doubt s/he will be able to go very far with their project (assuming it's being used for a hack). Edited November 27, 2005 by PlausiblyDamp Quote
Leeus Posted December 12, 2003 Author Posted December 12, 2003 No seriously, its not going to be used for hacking, I work for an isp and we have huge issues with our customers being open for relay, so this app just checks for that! I could have plumbed in our ip ranges but is seems to do the trick! Thanks guys! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.