Pesquisar este blog

quinta-feira, 18 de março de 2021

Linha de comando para verificar todos os IP da rede

 

Batch - Verificar endereço IP 

2017-2 - GTI  

 

for /L %%A in (1, 1, 254) do ( ping 10.66.28.%%A >> endereco.txt ) 

Batch para fazer a identificação de portas usando o NMAP 

2017-2 - GTI  

 

for /L %%A in (1, 1, 254) do ( c:\nmap\nmap-7.60\nmap.exe  -sV 10.66.28.%%A >> portas.txt ) 

Ou 

c:\nmap\nmap-7.60\nmap.exe  -sV 10.66.28.1-254 >> portas.txt 

BATCH - Verificar endereço IP - Isolando o resultado 

2017-2 - GTI  

for /L %%A in (1, 1, 254) do  

( 

 ping 10.66.28.%%A >> endereco.txt 

 find "Resposta de 10.66.28.%%A: bytes" C:\Users\cesar\endereco.txt >> C:\Users\cesar\limpo.txt 

) 

PLANILHA DE CALCULO DE ENDEREÇAMENTO IP 

2017-2 - GTI  

 

 

Comandos para filtrar somente os endereços IP e Portas de arquivo do NMAP   

2017-2 - ADS 

 

Comando que gera os dados para serem filtrados 

 

" c:\nmap\nmap-7.60\nmap.exe -sV 10.66.28.1-245 >> portas.txt "; 

 

Comando que filtra somente os endereços IP e portas abertas do arquivo originado do comando: 

 

" sed '/^S/d;/^=/d' portas.txt | awk '/[0-9]$/ {print " IP: " $5 "\n PORTS:\n"} /^[0-9]+\// {print "\t" $1,$2,$3 "\n"}' portas.txt > saida.txt " 

 

COMANDOS PARA FILTRAR SOMENTE O ENDEREÇO E O IP DO ARQUIVO NMAP  

 

nmap.exe -sV 127.0.0.1 >> portas.txt 

 

sed -n "/^[[:digit:]]\|scan report/p" portas.txt | gawk -f com.gawk 

 

com.gawk: 

/Nmap/{ 

print "IP: " $5 

valor = 1 

        print "Portas: " 

} 

!/Nmap/{ 

print $1 

} 

  

COMANDOS PARA FILTRAR SOMENTE O ENDEREÇO E O IP DO ARQUIVO NMAP  

 

EXECUTEI O NMAP PARA LISTAR AS PORTAS, COM O COMANDO: 

 

nmap.exe  -sV 192.168.0.107 >> portas.txt 

 

FILTREI AS LINHAS QUE TINHAM A PALAVRA 'OPEN'  E COLOQUE EM OUTRO ARQUIVO, COM O COMANDO: 

 

sed.exe -n "/open\|scan report/p" portas.txt > todasPortas.txt 

 

AGORA, FILTREI PARA PEGAR SOMENTE A PRIMEIRA COLUNA E A TERCEIRA, QUE SE REFEREM A PORTA E O SERVIÇO DELA. 

 

gawk.exe -f comandosGawk.txt portasFim.txt >> portasFinal.txt 

 

O conteúdo de 'comandosGawk.txt' possui os comandos:  

" /scan report/{ 

Print "IP: " $5 

} 

!/scan report/{ 

Print "Porta: " $1 " - Serviço: " $3  

}"  

O comando a cima, mostra para todas as linhas que tem a palavara "scan report", O texto "IP: (conteudo da 5 coluna)". 

Em seguida, exibe para todas as linhas que Não tenham 'scan report', conteudo da 1º coluna concatenado com as strings entre aspas junto com o conteudo da 3 coluna. 

 

EXERCICIO DE BDA  Listar os Pedidos do cliente ABRAHAO TEIXEIRA SERRAO 

 

SELECT * FROM pedido 

INNER JOIN cliente ON pedido.cd_cli = cliente.cod_cli where cliente.nome_cli = "ABRAHAO TEIXEIRA SERRAO"; 

 

RESOLUÇÃO DE PROBLEMAS - IDENTIFICAÇÃO DE TIPO DE CAMPO EM SQL_SCRIPT  

2017-2 - GTI 

 

Identificação de tipo de campo 

 

create table cliente ( 

cod_cli  smallint  not null, nome_cli varchar(40) not null, endereco  varchar(40)   null, cidade        varchar(20)    null, cep    char(08)       null, uf    char(02)       null, primary key (cod_cli)); 

 

create table vendedor ( 

cod_vend smallint not null, nome_vend varchar(40) not null, sal_fixo      double(9,2) not null, 

faixa_comiss    char(01)    not null, primary key (cod_vend)); 

 

create table produto ( 

cod_prod smallint not null, unid_prod char(03) not null, desc_prod varchar(20) not null, val_unit double(9,2) not null, primary key (cod_prod)); 

 

create table pedido 

( 

num_ped smallint not null, prazo_entr smallint  not null, cd_cli        smallint    not null 

REFERENCES CLIENTE (cod_cli), 

cd_vend    smallint    not null REFERENCES VENDEDOR (cod_vend), 

primary key (num_ped)); 

 

create table item_pedido ( 

no_ped    smallint    not null REFERENCES PEDIDO (num_ped), 

cd_prod    smallint    not null REFERENCES PRODUTO (cod_prod), 

qtd_ped    float    not null); 

 

 

 

CÓDIGO DO POWERSHELL PARA ACESSO À BANCO DE DADOS 

#Na tela principal acessar a pasta principal do computador 

 

cd\ 

********************************************************************************************************************* 

#Carregar o conector do banco para habilitar a conexão com o Banco de dados. 

 

 [void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") 

 

********************************************************************************************************************* 

 

#Comando de conexão com o banco  - deve estar habilitado o xampp para liberar a comunicação 

 

Function Run-MySQLQuery { 

 

Param( 

        [Parameter( 

            Mandatory = $true, 

            ParameterSetName = '', 

            ValueFromPipeline = $true)] 

            [string]$query,    

[Parameter( 

            Mandatory = $true, 

            ParameterSetName = '', 

            ValueFromPipeline = $true)] 

            [string]$connectionString 

        ) 

Begin { 

Write-Verbose "Starting Begin Section"  

    } 

Process { 

Write-Verbose "Starting Process Section" 

try { 

 

[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") 

$connection = New-Object MySql.Data.MySqlClient.MySqlConnection 

$connection.ConnectionString = $ConnectionString 

Write-Verbose "Open Database Connection" 

$connection.Open() 

 

 

Write-Verbose "Run MySQL Querys" 

$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $connection) 

$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command) 

$dataSet = New-Object System.Data.DataSet 

$recordCount = $dataAdapter.Fill($dataSet, "data") 

$dataSet.Tables["data"] | Format-Table 

 

catch { 

Write-Host "Could not run MySQL Query" $Error[0]  

 

Finally { 

Write-Verbose "Close Connection" 

$connection.Close() 

} 

    } 

End { 

Write-Verbose "Starting End Section" 

} 

} 

 

 

********************************************************************************************************************* 

 

#Comando que estabelece EFETIVAMENTE a comunicação com o banco que você quer buscar os dados. ALTERAR USUARIO, SENHA E NOME DO BANCO 

 

$connString = "Server=localhost;Uid=SEUUSUARIO;Pwd=SUASENHA;database=NOMEDOSEUBANCODEDADOS;" 

  

 

#NO EXEMPLO ABAIXO O COMANDO ATUALIZA O NOME DE UM ITEM NA TABELA DO BANCO E LISTA A TABELA COMPLETA 

 

[array]$sQLDings += "UPDATE NOMEDOSEUBANCODEDADOS.NOMEDASUATABELADOBANCO SET NOMEDACOLUNADATABELA ='XXXXXXXXXXXX' WHERE NOMEDACOLUNADATABELA like 'XXXXXXXXXXXXXXXXX'" 

[array]$sQLDings += "SELECT * from controle.cliente" 

  

foreach($sQLquery in $SQLDings) { 

run-MySQLQuery -connectionString $connString -query $sQLquery