首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用不同的文本替换.txt或数组中的{ text }

用不同的文本替换.txt或数组中的{ text }
EN

Stack Overflow用户
提问于 2022-05-04 07:26:36
回答 1查看 85关注 0票数 0

考虑在.txt文件中包含以下字符串

代码语言:javascript
复制
127.0.0.1
127.0.0.2
127.0.0.3

或者在数组中:

代码语言:javascript
复制
{"127.0.0.1","127.0.0.2","127.0.0.3"}

并考虑将以下字符串放入不同的.txt文件:

代码语言:javascript
复制
curl -sS -L https://github.com/vulmon/Vulmap/archive/master.tar.gz -o vulmap.tgz && echo y | sshpass -p 'ubuntu' scp -q ./vulmap.tgz ubuntu@192.168.74.133: && echo y | sshpass -p '{password}' ssh {username}@{ip} "mkdir -p ~/tmp-vulmap && cd ~/tmp-vulmap && tar -xzf ../vulmap.tgz && rm ../vulmap.tgz && cd ./Vulmap-master/Vulmap-Linux && python3 vulmap-linux.py"
代码语言:javascript
复制
curl -sS -L https://github.com/D0cT0r-inf0s3c/Praus/archive/master.tar.gz -o praus.tgz && echo y | sshpass -p 'ubuntu' scp -q ./praus.tgz ubuntu@192.168.74.133: && echo y | sshpass -p '{password}' ssh {username}@{ip} "mkdir -p ~/tmp-praus && cd ~/tmp-praus && tar -xzf ../praus.tgz && rm ../praus.tgz && cd ./Praus-master && (echo; echo 2; echo 1; echo 8; echo; echo 3; echo; echo 1;) | sudo bash praus.sh"
代码语言:javascript
复制
curl -L https://github.com/speed47/spectre-meltdown-checker/archive/master.tar.gz -o spectre-meltdown-checker.tgz && sshpass -p '{password}' scp -q ./spectre-meltdown-checker.tgz {username}@{ip}: && sshpass -p '{password}' ssh {username}@{password} "mkdir -p ~/tmp-BeRoot && cd ~/tmp-spectre-meltdown-checker && tar -xzf ../spectre-meltdown-checker.tgz && rm ../spectre-meltdown-checker.tgz && cd ./spectre-meltdown-checker-master && ./spectre-meltdown-checker.sh"

是否有可能用IP替换字符串{ip}?对于用户名和密码,用户输入的参数将被解析。如果{ip}能够工作,那么我也会找到这两个。

条件:

  • 代码将并行运行,因此在必要时循环遍历第一个.txt文件并将这些文件保存在变量中可能很方便。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-06 09:57:23

我已经找到了解决这个问题的办法:

代码语言:javascript
复制
public class Test
{
    public static void Main()
    {
        string replace = @"{ip}";
        //Hosts & programs
        string whosts = @"/hosts/windows.txt";
        string lhosts = @"/hosts/linux.txt";
        string defaultprofile = "programs.config";
        //IP Locations
        string llocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + lhosts;
        string wlocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + whosts;
        //string[] ips = { "127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6", "127.0.0.7", "127.0.0.8", "127.0.0.9", "127.0.0.10", "127.0.0.0" };
        //Read winips and linips
        List<string> winhosts = File.ReadAllLines(wlocation).ToList();
        List<string> linhosts = File.ReadAllLines(wlocation).ToList();
        ParallelOptions? options = new() { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = CancellationToken.None };
        //Check if windows.txt contains any hosts
        if (winhosts.Any())
        {
            string[] lines = File.ReadAllLines(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"/example/" + defaultprofile);
            List<string> winprograms = lines.SkipWhile(x => x != "WINVULNSCAN:")  // skips everything before 
            .Skip(1)                           // and <rs:data> itself
            .TakeWhile(x => x != "LINVULNSCAN:") // and take up to </rs:data>
            .ToList(); //Converts it to a List
            Parallel.ForEach(winhosts, host =>
            {
                Parallel.ForEach(winprograms, line =>
                {
                    string? result = line.Replace(replace, host);
                    Console.WriteLine(result + Environment.NewLine);
                });
            });
        }
        //check if linux.txt contains any hosts
        if (linhosts.Any())
        {
            string[] lines = File.ReadAllLines(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"/example/" + defaultprofile);
            List<string> linprograms = lines.SkipWhile(x => x != "LINVULNSCAN:")  // skips everything before 
            .Skip(1)                           // and <rs:data> itself
            .TakeWhile(x => x != "OTHERVULNSCAN:") // and take up to </rs:data>
            .ToList(); //Converts it to a List
            Parallel.ForEach(linhosts, host =>
            {
                Parallel.ForEach(linprograms, line =>
                {
                    string? result = line.Replace(replace, host);
                    Console.WriteLine(result + Environment.NewLine);
                });
            });
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72109303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档