Split string in multiple variables of 100 domains each.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Split string in multiple variables of 100 domains each.

#1 Post by JuanMa777 » 04 Jul 2017 16:05

Hi,
I'm writing a code to do massive dns queries, but my tool to do it can't handle my full lists of domains.
I thinks that my tool cant manage 100 quiries aprox.
How can I do to split my full lists in many variables to do many quiries?
The begin of my code is this:

Code: Select all

@echo off
title script para footprinting
cls
rem Extract the domains from a list of e-mails and dump in a .txt
for /f "tokens=2 delims=@" %%a in (%1) do echo %%a >>temp_lista-1.txt
rem Convert the list from vertical format to horizontal format and dump in a new file
for /f "usebackqdelims=" %%a in (temp_lista-1.txt) do @<nul set /p "=%%a" >>temp_lista-2.txt
rem Parse the horizontal file and set all domains in a variable.
rem Here is were I need to set multiple variables of 100 domains only.
for /f "delims=" %%a in (temp_lista-2.txt) do set n=%%a


In the code is explained with rem that I need.
Thanks for the help.

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Split string in multiple variables of 100 domains each.

#2 Post by JuanMa777 » 07 Jul 2017 07:34

Hi,
first of all sorry for the double post, but since I did not see answers I decided to do this.
I have made some progress.
The code is this (the call command and other "adjuncts" that do the code dirty are because this: http://www.dostips.com/forum/viewtopic.php?t=3160):

Code: Select all

@echo off
set str=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
for /l %%a in (1,3,20) do set num_1=%%a&call :next
goto :skip
:next
set /a num_2=%num_1%+2
for /f "tokens=%num_1-num_2% delims= " %%a in ("%str%") do echo %%a
goto :eof
:skip
pause


The idea is, for example, that the output is:
1 2 3
4 5 6
7 8 9
etc.

The new problem is that tokens=%num_1% alone work, but if I want implement the interval %num_1%-%num_2% in tokens don't work.
Any trick or solution?
Thanks.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Split string in multiple variables of 100 domains each.

#3 Post by Aacini » 07 Jul 2017 10:18

JuanMa777 wrote:Any trick or solution?
Thanks.

You should be careful on what you ask for, because you may get it! :shock: :lol:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set str=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

set p=%%
set /A i=1, j=0
set "part[!i!]= %str: =" & set /A j=(j+1)!p!3, i+=^^^!j & call set "part[!i!]=!p!part[!i!]!p! %"

set part

Output:

Code: Select all

part[1]= 1 2 3
part[2]= 4 5 6
part[3]= 7 8 9
part[4]= 10 11 12
part[5]= 13 14 15
part[6]= 16 17 18
part[7]= 19 20

This method is fully described at this thread.

Antonio

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Split string in multiple variables of 100 domains each.

#4 Post by JuanMa777 » 07 Jul 2017 14:33

Hi Aacini!,
In first place sorry for haven't read your previous post, :cry: .
Respect of your actual answer: :D :shock: :D . You are great in this!
The code works perfect, with my actual skills I would never have come to that, so thank you very much.
If I needed to do it some modifications first try (to learn...) and then I ask to you and all again.

Code: Select all

set saludos_manito=Thanks and regards!
echo %saludos_manito%

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Split string in multiple variables of 100 domains each.

#5 Post by JuanMa777 » 08 Jul 2017 16:29

Hola Antonio,
I'm testing your code but I have a problem now.
If I set a variable that have more of 101 domain names your code don't work. My strings need to support more than 5000 elements generally, and split in x elements (100 I suppose).
I was modifying your code trying to solve that, but I can't.
I can split my variable in x elements through change the number in "set /a j=(j+1)!p!3" but if the variable is longer than 101 the code don't run.
It is posible to modify the cuantity of the variable lenght that handle your code through it?
Regards.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Split string in multiple variables of 100 domains each.

#6 Post by Aacini » 08 Jul 2017 17:11

This method have a restriction on the maximum length of the variable, because it is expanded changing each space by several characters. However, this method is the wrong approach to solve your problem. I think the right solution should be this one:

Code: Select all

@echo off
title script para footprinting
cls
rem Extract the domains from a list of e-mails and dump in a .txt file
rem with lines of 100 domains each
set i=0
(for /f "tokens=2 delims=@" %%a in (%1) do (
   set /p "=%%a"
   set /a "i=(i+1)%%100"
   if !i! equ 0 echo/
)) <nul >temp_lista.txt

¡Saludos desde México! :D

Antonio

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Split string in multiple variables of 100 domains each.

#7 Post by JuanMa777 » 08 Jul 2017 19:19

Hi Antonio,
I have joined your code with this other and seem that work well. I'll still try it anyway.
This is the result:

Code: Select all

@echo off
title script para footprinting
cls
rem setting file_1 because the delayed expansion
set file_1=%1
setlocal enabledelayedexpansion
set i=0
(for /f "tokens=2 delims=@" %%a in (!file_1!) do (
   set /p "=%%a "
   set /a "i=(i+1)%%100"
   if !i! equ 0 echo/
)) <nul >temp_lista.txt
set i=0
for /f "tokens=*" %%a in (temp_lista.txt) do (
    set /a i+=1
    set str_!i!=%%a
)


Can you remove some superfluous things? Example, join i variables of to codes, etc.
I'm working in avoiding a file creation, but don't work.
Perhaps you can do it work.
This is the code:

Code: Select all

@echo off
title script para footprinting
cls
set file_1=%1
setlocal enabledelayedexpansion
set i=0
(for /f "tokens=2 delims=@" %%a in (!file_1!) do (
   set /p "=%%a "
   set /a "i=(i+1)%%100"
   if !i! equ 0 for /f "tokens=*" %%b in (%%a) do set str_!i!=%%b
)
)


Regards!

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Split string in multiple variables of 100 domains each.

#8 Post by Aacini » 09 Jul 2017 11:26

Ok. You should note that you have not explained what is your real problem! The title of this topic is "Split string in multiple variables" and your example code tries to do that using disk files...

After read this thread several times I assumed that you have a DNS program that do queries on the domains given in the parameters, like this one:

Code: Select all

dnsQuery.exe domain1 domain2 ...

... but such a program can handle a maximum of 100 parameters and you have much more domains in a text file with e-mails. If this is the problem, then a possible solution is this:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

title script para footprinting
cls

rem Extract the domains from a list of e-mails, join them in groups of 100 domains each
rem and execute the DNS query program with each group

set i=0
set "domains="
for /f "tokens=2 delims=@" %%a in (%1) do (
   set "domains=!domains!%%a"
   set /a "i=(i+1)%%100"
   if !i! equ 0 (
      dnsQuery.exe !domains!
      set "domains="
   )
)
if %i% gtr 0 dnsQuery.exe %domains%

I encourage you to read the first topic of this forum...

Antonio

Post Reply