понеделник, януари 23, 2023

Windows CLI get file from Internet (like wget or curl)

CMD: (bitsadmin is depricated)

 bitsadmin /transfer <DownloadJobName> /download /priority normal http://example.com/example.txt C:\example.txt

BITSAdmin tool does not provide an option to ignore certificate errors

PS: 

Invoke-WebRequest -Uri http://example.com/example.txt -OutFile C:\example.txt

Start-BitsTransfer -Source http://example.com/example.txt -Destination C:\example.txt

Invoke-WebRequest -Uri https://example.com/example.txt -OutFile C:\example.txt -SkipCertificateCheck

(to skip certificate errors)

петък, януари 06, 2023

Notepad++ Find & Rеplace IP Addresses

 Find & Rеplace IP Addresses in TXT file Regular Expression/ RegEx IP

 

За намиране на адрес без маска -        (\d{1,3}\.){1,3}\d{1,3}\/\d{1,2}

За намиране на адрес с маска -             (\d{1,3}\.){1,3}\d{1,3}\/\d{1,2}\/d{2}

 

CTRL+H

((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))



Replace 10.0.0.%2 with %1

  • Ctrl+H
  • Find what: (10(?:\.\d{1,3}){3})%2
  • Replace with: $1%1
  • Replace all

Explanation:

(               : start group 1
  10            : literally 10
  (?:           : start non capture group
    \.\d{1,3}   : a dot followed by 1 to 3 digits
  ){3}          : group must appear 3 times
)               : end group 1
%2              : literally %2

  • Check regular expression
  • DO NOT CHECK . matches newline

Replacement:

$1      : content of group 1
%1      : literally %1

 

Or another option:

 

  • Ctrl+H
  • Find what: ^.+?((?:\d+\.){3}\d+).+$
  • Replace with: $1
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

^           : beginning of line
.+?         : 1 or more any character but newline
(           : start group 1
  (?:       : start non capture group
    \d+     : 1 or more digit
    \.      : a dot
  ){3}      : end group, must appear 3 times
  \d+       : 1 or more digit
)           : end group 1
.+          : 1 or more any character but newline
$           : end of line

Replacement:

$1          : content of group 1 (ie. the IP)

Result for given example:

54.246.81.158
175.36.129.24

To be sure you have an IP address, use

((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))

instead of

((?:\d+\.){3}\d+)

 

From <https://superuser.com/questions/1321363/how-to-extract-ip-address-from-the-logs-string-with-regular-expression-and-note>

 

Notepad++ replace/remove a line containing sting

 

Replace/remove the line containing word < string>

 

Find/Replace dialog and with regex:

 

1.  Ctrl + h to bring up the find replace dialog.

2.  In the Find what: text box include your regex: .*string.*\r?\n (where the \r is optional in case the file doesn't have Windows line endings).

3.  Leave the Replace with: text box empty.

 

    Make sure the Regular expression radio button in the Search Mode area is selected. Then click Replace All and voila! All lines containing your search term help have been removed.

 

 

  • Go to the search menu, Ctrl + F, and open the Mark tab.
  • Check Bookmark line (if there is no Mark tab update to the current version).
  • Enter your search term and click Mark All
    • All lines containing the search term are bookmarked.
  • Now go to the menu SearchBookmarkRemove Bookmarked lines
  • Done.