我的资源中有一个名为TextIPS的文本文件(包含大约4000个IP地址的列表)
我想要一个能够获取该文本文件的随机行然后将其写入文本框的函数。
让我们说文本文件包含5行
当我单击一个按钮时,我希望它获取这5个值中的任何一个,然后将获取的值写入文本框。
答案 0 :(得分:1)
以下是代码示例:
Private rdm As New Random
Private Function GetRandom(max As Integer) As Integer
'rdm.Next(minValue, maxValue) returns a random number greater than or equal to minValue and less than maxValue.
Return rdm.Next(0, max)
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IpAddresses() As String = File.ReadAllLines(My.Computer.FileSystem.SpecialDirectories.Desktop & "\TextIPS.txt")
Dim RandomIpAddress As String = IpAddresses(GetRandom(IpAddresses.Length))
MsgBox(RandomIpAddress)
End Sub
答案 1 :(得分:1)
没关系我弄清楚了。我将ip上传到原始的pastebin页面并添加了这段代码
Dim wc As New System.Net.WebClient
Dim r As New Random
Dim RndIpAddress As String() = wc.DownloadString(IPAddressList).Split(Environment.NewLine)
ParseIP(RndIpAddress(r.Next(1, RndIpAddress.Length)))
使用IPAddressList作为原始pastebin页面的链接