Saturday, August 7, 2021

Markdown on medium

Today I would like to shar on how to use some MD in medium, some markdown might not work the same in githb. 


Write code use the command to switch:

  • Windows : ctrl+alt+6
  • Mac : command+ option+6
  • Linux : ctrl+alt+6


Markdown with code single line:  `code `
Markdown with multiply line:  ```code ```
Slice line: is quite different, the normal way is ~~text~~, but Medium need to go to web and generate it. 
https://www.piliapp.com/cool-text/strikethrough-text/
https://fsymbols.com/generators/strikethrough/



Saturday, July 31, 2021

selenium scroll

 his is a HTML :

reference: https://michaeljsanders.com/2017/05/12/scrapin-and-scrollin.html

import time
from selenium import webdriver
from bs4 import BeautifulSoup as bs
# I used Firefox; you can use whichever browser you like.
browser = webdriver.Chrome()
# Tell Selenium to get the URL you're interested in.
browser.get("http://URLHERE.com")
# Selenium script to scroll to the bottom, wait 3 seconds for the next batch of data to load, then continue scrolling.  It will continue to do this until the page stops loading new data.
lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
    match=False
        while(match==False):
                lastCount = lenOfPage
                time.sleep(3)
                lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
                if lastCount==lenOfPage:
                    match=True
# Now that the page is fully scrolled, grab the source code.
source_data = browser.page_source
# Throw your source into BeautifulSoup and start parsing!
bs_data = bs(source_data)




Sunday, July 11, 2021

conda not found in MAC

 Have you ever see an issue in MAC when Anaconda is been installed propely and the conda is place correctly but still conda will be not found. I'm going to teach you how to solve this issue: 


Part1 In case you don't know how to add CONA to PATH

Note: Mac Anaonda is been save in /opt/anaconda3

1. Edit vim ~/.bash_profile

export PATH="/opt/anaconda3/bin:$PATH"

2. wq! or x! to save it 

3. source ~/.bash_profile

4. you can check PATH  by:   echo $PATH

conda --version

6 open a new terminal and enter conda --version will occur command not found 

Part 2 Terminal running conda 

To solve this issue we basely have to just touh a file. In MAC default it uses zshrc

Method1:  

1. touch ~/.zshrc 

2. edit it 

source ~/.bash_profile

3. save it by wq! or x!

4. open new terminal and press coda--version will fix this problem


Method2: 

1. go to system preferences>user&groups> 

2. unlock your setting 

3 click on a username and right-click and select advance option

4. login shell changed to /bin/bash will fix this

Saturday, May 15, 2021

Selenium Xpath



 Today I wants to share Xpath using selenium. Xpath is a unique tool, which is better than other finding_element. These are the following element you can use:

find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector

or multiply element 

find_elements_by_id
find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector


I think to know XPath is really important.

The syntax of it is: 

Xpath=//tagname[@attribute='value']

This is a HTML :

<html>
 <body>
  <p>Are you sure you want to do this?</p>
  <a href="continue.html">Continue</a>
  <a href="cancel.html">Cancel</a>
  <form id="loginForm">
    <input name="username" type="text" />
    <input name="password" type="password" />
    <input name="continue" type="submit" value="Login" />
    <input name="continue" type="button" value="Clear" />
    <div class="search">
      This is new page<h1>Hello</h1>!!!!!
    </div>
</form>
</body>
</html>

  • If you want to get the name for the username, you can try like this:

//input[@name='username']

  • using chrome development tool to get xpath. The [1] is username, [2] is password ....[4]

//*[@id="loginForm"]/input[1]
//*[@id="loginForm"]//input[@name="username"]

  • Full path using chrome development tool

/html/body/form/input[1]

you can see the input name for clear and login is the same "continue", if we want to get the clear button:

//input[@name='continue'][@type='button']

or

//*[@id="loginForm"]/input[4]


You can also use some function text(), or contain

If you use JUST text(), the string must be the same, else won't find it

 //*[text()="str"]
 //*[contains(text(),'str')]

if I want to find "continue", I can use this:

//*[text()="Continue"]

or 

 //*[text()="Cont"] 

using (dot)

Sometimes when you used  text() or contain() to find, but will not be able to find, you can use this method:

For example, this is Instagram following text, which can't find the following, you have to use this method. 


//*[text()[contains(.,'str')]]

//*[contains(.,'str')]


this will search from the root to the current node. 

Selenium with Xpath

inorder to use in selenium you have to use like this|:

driver.find_element_by_xpath('put-your-xpath-here').click()



Sunday, January 3, 2021

download VIDEO STREAMING tool

 There are many different type of download video streaming tool.  I believe many people used it before, but I still wants to share it to you. 


Before introduce this tool, I would like to teach how to capture video streaming file from browse. I believe from people would know that when I mention about browser you would reflect it to devtool, well that's right. I am using the devtool to teach how to capture the stream, which is pretty good tool to used.


I like to used YouTube as an example, please notice that youtube steaming split the audio and video stream into two part, the file for video will be webm, and audio would be weba. 

Today many web development's security are improvement, some site would not be easy to capture. 

Procedure: 

1. Lauch your site to youtube and click any video you like

2. left click and presss "inspect"

3. go to "network" and go to xhR 

you can see there is a playlist, click on it, you will see the url requst, and content type to make sure it's video type. Note that each pair will have one video one audio stream. 

4. select the url and right click to direct to the page and download it. (downlaod both audio and video)




The next thing I wants to intoduce the tool, whic is FFMPEG, this is an oepnsource tool, but it's not GUI, you need to type this command. This tool is to convert the file to any format you like. If you have a mp4 file, and can also convert to mp3. You don't have to used any other tool. 

Got to this page to download it: https://ffmpeg.org/download.html

You can click on documentation to understand more command. 

I will only teach you 2 command: 

1. convert single file: ffmpeg -i filename xxx.[mp3 or mp4 or any file you want)

ffmpeg -i video.mp4 mysong.mp3

2. convert audio and video and merge into one file. 

ffmpeg -i video.webm -i audio.weba -c:v copy -c:a aac myvideo.mp4

After you know the command, and download ffmpeg tool, put the two file you download from youtube and copy it into the same directory and used the second command will be able to see the video. 

But there is another tool you can use it's much easier, called youtube-dl, command is youtube-dl "youtube url" that's it, you don't need to open devtool. 


Thursday, December 17, 2020

scanning port (NMAP)

 

TCP:

nmap -v -sT -T2 -Pn -p T:5060,111,65431,44318,4159,80,443,53 IPv4-Address

nmap -v -sT -T2 -Pn -p T:52224,705,111,51413,37915,4159,22,23 -6 IPv6-Address

UDP:

nmap -v -sU -T2 -Pn -p U:1293,111,161,162,3000,5060,546,53  IPv4-Address

nmap -v -sU -T2 -Pn -p U:1293,111,2427,161,162,3000,546 -6  IPv6-Address


hping IP Flood attack to DUT


 1. Connect a LAN PC to DUT via ethernet. Do " ping  8.8.8.8 -t" and access websites, can success.

2. Use hping3 command " hping3 -S -P -U --flood -V --rand-source DUT-IP" ( DUT's  IP) to attack DUT WAN IP.

3. After a while, no more than 1 minutes, LAN PC can not ping successfully, and can not access internet.

4. Use hping3 command "hping3 -1 --flood -V target" generate icmp flood to attack DUT WAN IP.

5. After a while, LAN PC can not ping successfully, and can not access internet.