Sunday, November 16, 2014

How to Read Food Nutrition Label and Use it to Lose Weight.

Nutrition Facts is a label required on all the packaged food in most of the countries. In this post, I'm gonna tell you how to understand that label.

Let's take a simple example Lays (28g pack)-

8 major parts of Nutritions Facts Label

  1. Serving Size(g): It tells about recommend serving size, so if your serving size is 2 then you'll be eating double the calories.
  2. Total Calories(cal/Kcal): Total calories and Calories from Fat in 1 serving. You can calculate approx. total calories by Nutrition facts
    [Total calories(kcal) = (Fat x 9) + (Carbohydrate x 4 ) + (Protein x 4) ]
  3. Total Carbohydrates(g): are made up of Dietary Fiber and Sugars. Fiber help us to prevent Chronic Diseases. It is recommended to consume 25g of dietary fiber per day. Whole grains, beans and fruits are good source for fiber. One gram of Carbohydrates is approx. equal to 4 cal.
  4. Total Fat(g): tells all types of fats in grams. One should not take more then 20% of required calories per day from Fat. You can check various types of Fats here. Polyunsaturated and Monounsaturated are the healthy Fats, while Trans and Saturated Fats are unhealthy(tends to increase LDL which is bad Heart and increases Blood Pressure). One gram of Fat is approx. equal to 9 cal.
  5. Protein(g): a healthy individual  should take more than 20% of required calories from Proteins. Dairy product, peas, sprouts, eggs, meat and nuts are good source of proteins. One gram of Protein is approx. equal to 4 cal.
  6. Sodium: increases risk of high blood pressure. One should not consume Sodium more then 1000mg per day.
  7. Cholesterol: found in bloodstream. Higher Cholesterol can clog arteries so increase the risk of heart disease.
  8. Vitamins & Minerals: Here comes the best part of food which promotes good health and prevent diseases. you can check required value per day on wiki page. Source of Vitamins can be Meat, fish, poultry, Leafy green vegetables, fruits, Milk and milk products,enriched breads and cereals.




Weight Loss / Weight Gain Examples

Your body needs energy for breathing, circulating blood, repairing cells and all other bodily functions. Making sure you eat enough food can help ensure that your body has enough energy to develop and work properly. Our metabolism and how many calories your body needs each day is influenced by your age, gender and physical activity habits which can be calculated from here.

  • Weight Loss/Gain: As you already know, One gram of Fat is equal to 9 cal. So to reduce 100g of weight (Fat) either you should intake 900 calories less or you should burn 900 calories by Exercise (1km running burns around 80 calories ). Rest is maths, you can calculate how much exercise is needed to lose x grams of weight. Below you can find Calorie Sheet of common foods.


Hopes, It will be helpful for you.
Cheers!!

Saturday, November 8, 2014

HPing: How to generate TCP traffic

Hping is a network tool able to send custom TCP/IP packets and to display target replies like ping program does with ICMP replies. HPING can be used to create IP packets containing TCP, UDP or ICMP payloads. All header fields can be modified and controlled using the command line. If interface MTU less then Payload then packet will be fragmented but in case of SendIP, packet will be dropped by Linux Cllient.

How To Install

Download Tarbell package from here.
Steps to install:
  1. Untar it in some folder. (tar -xzvf hping2.0.0-rc2.tar.gz)
  2. Goto hping folder ( cd hping2-rc2/ )
  3. ./configure
  4. sudo make
  5. make install
  6. Now if you do 'hping2 --h' on Linux CLI, It should show all the options available.

How To Use


Basic Options:
  • -c --count  //count Stop after sending (and receiving) count response packets
  • -i --interval  //Wait the specified number of seconds or micro seconds between sending each packet. --interval X set wait to X seconds, --interval uX set wait to X micro seconds.
  • -I --interface  //interface name
  • -V --verbose  //Enable verbose output. TCP replies will be shown as follows: len=46 ip=192.168.1.1 flags=RA DF seq=0 ttl=255 id=0 win=0 rtt=0.4 ms tos=0 iplen=40 seq=0 ack=1380893504 sum=2010 urp=0


Protocol Selection:

  • Default protocol is TCP, by default hping2 will send tcp headers to target host's port 0 with a winsize of 64 without any tcp flag on.
  • -1 --icmp //ICMP mode, by default hping2 will send ICMP echo-request, you can set other ICMP type/code using --icmptype --icmpcode options.
  • -2 --udp //UDP mode, by default hping2 will send udp to target host's port 0. UDP header tunable options are the following: --baseport, --destport, --keep.


Examples:

  • TCP: hping -p 23 -c 1 -P -A -s 36617 -d 1170 5.5.5.6 //-s source port,-p dest port,-w Set TCP window size. Default is 64.,-M --tcpseq,-F --fin,-S --syn,-R --rst, -P --push,-A --ack,-U --urg,-X --xmas,-Y --ymas
  • ICMP: hping -1 --icmptype 128 --icmpcode 0 5.5.5.6 // --icmptype --icmpcode, echo req - 8,0
  • UDP: hping -2 --baseport 34444 --destport 34567 5.5.5.6 //--baseport, --destport, --keep.


Wednesday, July 30, 2014

SendIP - an arbitrary IP packet generating tool

SendIP is a tool which allows creating (and, of course, sending) arbitrary IP (v4 and v6) packets.

How To Install

Download Tarbell package from here.
Steps to install:
  1. Untar it in some folder. (tar -xzvf sendip-2.5-mec-0.tar.gz)
  2. sudo make
  3. make install
  4. Now if you type sendip on Linux CLI, it should show all the available Modules. (Ex: ipv4 ipv6 icmp tcp udp bgp rip ripng ntp ah dest esp frag gre hop route)

How To Use


  • -p module //load the specified module (see below)
  • -v  be verbose
  • -h  print this message
  • -d  data //add this data as a string to the end of the packet. rN to generate N random(ish) data  bytes; //zN to generate N nul (zero) data bytes; 0x or 0X followed by hex  digits; 0 followed by octal digits; decimal number for decimal digits


Example:

  • ICMP4: sendip -v -p ipv4 -is 2.2.2.2 -p icmp -d r10 2.2.2.3 
  • ICMP6: sendip -v -p ipv6 -6s 9901::180 -p icmp -d "hello" 9901::100
  • TCP4 : sendip -v -p ipv4 -is 2.2.2.2 -p tcp -ts 1000 -td 1005 -tfs 1 -tn 0 2.2.2.3
  • TCP6 : sendip -v -p ipv6 -6s 9901::180 -p tcp -ts 1000 -td 1005 -tfs 1 -tn 0 9901::100
  • UDP4 : sendip -v -p ipv4 -is 2.2.2.2 -p udp -us 34001 -ud 34002 2.2.2.3
  • UDP6 : sendip -v -p ipv6 -6s 9901::180 -p udp -us 34001 -ud 34002 9901::100

Generate Various IPv6 Extension Header with ICMPv6 as next header.

  • Route(43):    sendip -v -p ipv6 -6s 9901::180 -6n 43 -p route -p icmp -d "hello" 9901::100
  • Frag(44): sendip -v -p ipv6 -6s 9901::180 -6n 44 -p frag -p icmp -d "hello" 9901::100
  • AH(51): sendip -v -p ipv6 -6s 9901::180 -6n 51 -p ah -p icmp -d "hello" 9901::100
  • HopByHop(0)sendip -v -p ipv6 -6s 9901::180 -6n 0 -p hop -p icmp -d "hello" 9901::100
  • Dest Opt(60)sendip -v -p ipv6 -6s 9901::180 -6n 60 -p dest -p icmp -d "hello" 901::100
  • ESC(50): sendip -v -p ipv6 -6s 9901::180 -6n 32 -p esc -p icmp -d "hello" 9901::100

Thursday, August 1, 2013

Capture and read packets in Linux CLI using TCPDUMP

tcpdump is a common packet analyzer that runs under the command line. It allows the user to intercept and display TCP/IP and other packets being transmitted or received over a network to which the computer is attached. Distributed under the BSD license, tcpdump is free software.

In this post, i will try to show you how to use tcpdump command and capture required package.
  • 'tcpdump' - capture the traffic passing through 'eth0' or management interface.
  • 'tcpdump -i eth1' -  use minus (-) i option to capture packet passing through eth1
  • 'tcpdump -e -i eth1' -  use minus (-) e option to capture packets passing through eth1 with ethernet header details.
  • 'tcpdump -i eth1 tcp' - capture tcp packets only which are passing through eth1
  • 'tcpdump -i eth1 tcp and src host 2.2.2.2' - capture tcp packets which is sent from 2.2.2.2
  • 'tcpdump -i eth1 tcp or src host 2.2.2.2' - capture tcp packets or packets whose src ip is 2.2.2.2
  • 'tcpdump -i eth1 tcp and greater 1000' - capture tcp packets whose length is greater then 1000B.
  • tcpdump -n -i eth1 tcp : minus (-) n used to avoid DNS lookups. Don't convert host addresses to names.
Save tcpdump in a file- use minus (-) w option which can be read using WhireShark.
  • 'tcpdump -i eth1 -w /dir/file.pcap tcp and host 10.102.174.42'
Read .pcap file using tcpdump
  • 'tcpdump -e -r src9.pcap | grep http'
All available filters that you can apply to capture required packets -
  • dst host 2.2.2.2  or dst host 9901::123 - destination host
  • host 2.2.2.2  or host 9901::123 - has this IP
  • ether src fa:38:3c:50:63:72
  • ether dst, ether host
  • src port 21
  • dst port 80
  • src portrange 10-90
  • less 100
  • vlan 5

Tuesday, July 30, 2013

Vi Editor basic user guide

vi is a screen-oriented text editor originally created for the Unix operating system.
Here are the few basic and necessary shortcuts to use vi editor effectively-
  • '0'(zero) -move cursor to start of current line
  • ':n' -move cursor to line n
  • ':$' -move cursor to last line in file
  • 'x' -delete single character under cursor
  • 'dd' -delete entire current line
  • 'dw' -delete the single word beginning with character under cursor
  • 'yy' -copy (yank, cut) the current line into the buffer
  • 'Nyy' -copy (yank, cut) the next N lines, including the current line, into the buffer
  • 'p' -put (paste) the line(s) in the buffer into the text after the current line
  • '/string' -search forward for occurrence of string in text
  • '?string' -search backward 
  • 'n'  -move to next occurrence of search string
  • 'N'  -search for previous occurrence 
  • 'u' -Undo last change
  • 'ctrl + r'  - Redo 
  • ':s/OLD/NEW/g'  -Replace OLD with NEW Globally (all) on current line
  • ':%s/OLD/NEW/g'   -Replace OLD with NEW Every occurrence in file

Sunday, July 28, 2013

Some Linux cli tips that you should know

In this post I'm giving few Linux CLI tips/shortcuts which i found very helpful and increase your speed while you are working on Linux using CLI. These tricks are very useful for those who are new to Linux.

  1. 'CTL+L' - Clear screen. (you can use 'clear' also to clear the screen).
  2. 'CTL+R' - Search recent commands from History.
  3. 'CTL+A' - Take the cursor to the start of current command.
  4. 'CTL+E' - Take the cursor to the end of currnet command.
  5. 'CTL+W' - To erase one word in current command.
  6. 'CTL+U' - To erase whole command.
  7. 'CTL+Y' - To type the above command which was erased by 'CTL+U'.
  8. 'CTL+D' - Exit or logout current session.
  9. 'screen' - run multiple session inside a single session. 'CTL+A' then 'N' to go to next session and 'CTL+A' then 'P' to go to previous session.
  10. 'CTL+C' - To halt current command
  11. 'CTL+Z' - Stop current command
  12. '!!' - Repeat previous command

Thursday, December 6, 2012

Some Basic Networking Commands : Linux/Windows

I this post i am gonna write about some basic Networking commands used in Windows/Linux that i found important.
  • Display Network configuration and interfaces
    1. windows : "ipconfig" or "ipconfig /all"
    2. Linux: "ifconfig" or "ifconfig interface-name"
  • Show all running Tasks/Applications
    1. windows : "tasklist
    2. Linux: "ps aux" or "top" (Top is used to show memory and CPU used by running process)
  • Kill a task
    1. windows : "taskkill -pid 4000" or "taskkill -im iexplore.exe" ( Here -im is for image name)
    2. Linux: "kill -9 pid"
  • Displays the active TCP connections and ports on which the computer is listening
    1. windows : "netstat -a"
    2. Linux: "netstat -an"
  • Diagnose the Domain Name System (DNS) : Resolves a hostname to IP address
    1. windows : "nslookup google.com
    2. Linux: "dig google.com"
  • Ping : tool used to test whether a particular host is reachable or not.
    1. windows/Linux IPv4 : "ping 74.125.236.73"
    2. Windows/Linux IPv6: "ping6 9901::1"
  • Path Ping : To see all the routers present in path to Destination
    1. windows : "pathping google.com
    2. Linux: "tracepath google.com"
  • Assign IP/Subnet to Linux interfaces
    1. Linux - IPv4 : "ifconfig eth0 192.168.1.2 netmask 255.255.255.0"
    2. or Linux - IPv4 : "ifconfig eth0 2.2.2.2/24"
    3. Linux - IPv6 : "ifconfig eth1 inet6 add 9901::2/64 "
  • Delete IP from Linux interfaces
    1. Linux - IPv4 : "ifconfig eth1 del 2.2.2.3 netmask 255.255.255.0"
    2. Linux - IPv6 : "ifconfig eth1 inet6 del 9901::2/64"
  • Change MTU(Maximum Transmit Unit through an Interface) of Linux interfaces
    1. Linux : "ifconfig interface_name mtu value"
    2. Linux : "ifconfig eth1 mtu 1300"
  • Print routing tables
    1. windows : "netstat -r" or "route print"
    2. Linux- IPv4: "route -A inet" or "route -4" or "ip route"
    3. Linux -IPv6: "route -A inet6" or "route -6" or "ip -6 route"
    • Add/Delete static routes
      1. windows- IPv4 : "route add 10.10.10.0 mask 255.255.255.0 192.168.1.12"
      2. Windows - IPv6 : "netsh interface ipv6 add route 9901::/64 "Local Area Connection" 2001::1"
      3. Linux-IP4: "route add -net 3.3.3.0 netmask 255.255.255.0 gw 1.1.1.1"
      4. Linux-IP4: "ip route add 3.3.3.0/24 via 1.1.1.1"
      5. Linux-IP6: "route -A inet6 add 9901::/64 gw 2001:0db8:0:f101::1"
      6. Linux-IP6: "ip -6 route add 9901::/64 via 2001:0db8:0:f101::1"
    • Trace route : to diagnostic tool for displaying the route
      1. windows : "tracert google.com"
      2. Linux: "traceroute google.com"
    • Secure Shell :SSH is a network protocol for secure data communication and remote command execution
      1. SSH-IPv4 : "ssh username@IPv4_address" Ex: ssh root@74.125.236.73 then it will ask you for password.
      2. SSH-IPv6: "ssh username@IPv6_address"  Ex : ssh username@9901::1.
    • Secure FTP : SFTP is a network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream.
      1. SFTP-IPv4 : "sftp username@IPv4_address". Ex: sftp root@74.125.236.73
      2. Linux: "sftp username@[IPv6_address]". Ex:  sftp username@[9901::15]
    • Secure Copy or SCP : Secure copy or SCP is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol.
      1. SCP Linux : scp  username@IP:/Dir/File_name /local_dir
      2. Ex:     scp  root@10.217.208.40:/root/roy.txt .
      3. SCP windows : For windows you can use, WinSCP. Its a GUI based tool.