net cat command

Netcat is a utility that’s used for sending and receiving messages over a network connection. Netcat is known as the Swiss Army knife of networking tools, and we’ll be using it to communicate directly with a server.

# sudo yum install nc nmap
[vagrant@localhost]$ nc google.com 80
GET / HTTP/1.1

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.co.jp/?gfe_rd=cr&ei=vdh5WPnNOK3K8gfgs5d4
Content-Length: 259
Date: Sat, 14 Jan 2017 07:52:29 GMT


302 Moved

302 Moved

The document has moved here.
[vagrant@localhost ruby3]$ nc example.com 80
HEAD / HTTP/1.1
Host: example.com

HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sat, 14 Jan 2017 07:55:51 GMT
Etag: "359670651+gzip"
Expires: Sat, 21 Jan 2017 07:55:51 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (rhv/818F)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 606
[vagrant@localhost ruby3]$ nc example.com 80
OPTIONS / HTTP/1.1
Host: example.com

HTTP/1.1 200 OK
Allow: OPTIONS, GET, HEAD, POST
Cache-Control: max-age=604800
Date: Sat, 14 Jan 2017 07:59:08 GMT
Expires: Sat, 21 Jan 2017 07:59:08 GMT
Server: EOS (lax004/280C)
x-ec-custom-error: 1
Content-Length: 0

HTTP/2 was developed by the IETF’s HTTP Working Group, which maintains the HTTP protocol. It’s made up of a number of HTTP implementers, users, network operators and HTTP experts.

Note that while our mailing list is hosted on the W3C site, this is not a W3C effort. Tim Berners-Lee and the W3C TAG are kept up-to-date with the WG’s progress, however.

A large number of people have contributed to the effort, but the most active participants include engineers from “big” projects like Firefox, Chrome, Twitter, Microsoft’s HTTP stack, Curl and Akamai, as well as a number of HTTP implementers in languages like Python, Ruby and NodeJS.

To learn more about participating in the IETF, see the Tao of the IETF; you can also get a sense of who’s contributing to the specification on Github’s contributor graph, and who’s implementing on our implementation list

HTTP request

HTTP /pictures/kitty.jpg /HTTP/1.1
HTTP /pictures/kitty.jpg /HTTP/2.0

header section below

HTTP /pictures/kitty.jpg /HTTP/2.0
Host: www.google.com
User-Agent: Mizilla/5.0
Connection: keep-alive
Accept: text/html
If-None-Match: fd87e6789

HTTP Response
—-
HTTP/1.1 200 OK
Content-Length: 16824 (※how many byte server send)
Server: Apache
Content-Type: text/html
Date: Wed, 06 Apr 2016
Etag: fd87e6789

binary data

http

fetch("http://www.example.com", {
	"method": "GET ",
	"headers": {

	}
});
fetch("password.txt", {
	"method": "PUT",
	"headers": {
		"exercise": "fetch rocks!"
	}
});

Port connection

22 for ssh
80 for http

The port range that a normal (non-root) user can listen on is 1024 through 65535.

Hosts:a machine on the internet that might host services

vagrant@vagrant-ubuntu-trusty-64:~$ ping -c 1 google.com
PING google.com (172.217.24.142) 56(84) bytes of data.
64 bytes from nrt20s01-in-f14.1e100.net (172.217.24.142): icmp_seq=1 ttl=50 time=87.3 ms
vagrant@vagrant-ubuntu-trusty-64:~$ host google.com
google.com has address 172.217.25.238
google.com has IPv6 address 2404:6800:4004:817::200e
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
vagrant@vagrant-ubuntu-trusty-64:~$ host -t a google.com
google.com has address 172.217.25.238
vagrant@vagrant-ubuntu-trusty-64:~$ dig www.udacity.com

; <<>> DiG 9.9.5-3ubuntu0.10-Ubuntu <<>> www.udacity.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42131
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.udacity.com.               IN      A

;; ANSWER SECTION:
www.udacity.com.        3081    IN      CNAME   apollo-mesos-elb-berlioz2-prod-885022263.us-west-2.elb.amazonaws.com.
apollo-mesos-elb-berlioz2-prod-885022263.us-west-2.elb.amazonaws.com. 33 IN A 54.186.129.122
apollo-mesos-elb-berlioz2-prod-885022263.us-west-2.elb.amazonaws.com. 33 IN A 52.26.227.216
apollo-mesos-elb-berlioz2-prod-885022263.us-west-2.elb.amazonaws.com. 33 IN A 35.163.216.178

;; Query time: 86 msec
;; SERVER: 10.0.2.3#53(10.0.2.3)
;; WHEN: Sat Dec 10 14:32:18 UTC 2016
;; MSG SIZE  rcvd: 160

CNAMEレコード 【 Canonical NAME record 】 CNAMEレコードとは、DNSで定義されるそのドメインについての情報の種類の一つで、あるドメイン名やホスト名の別名を定義するもの。
ドメイン名に対応するIPv6形式のIPアドレスが書いてある行が「AAAAレコード」
NSレコードは、ゾーン情報を管理するネームサーバー(DNSサーバー)名を定義するレコード

network address

vagrant@vagrant-ubuntu-trusty-64:~$ ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:6c:cb:39 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe6c:cb39/64 scope link
       valid_lft forever preferred_lft forever

my ip address
http://test-ipv6.com/

what server they use

nc send string over network.

vagrant@vagrant-ubuntu-trusty-64:~$ printf ‘HEAD / HTTP/1.1\r\nHost: www.google.co.jp\r\n\r\n’ | nc www.google.co.jp 80

HTTP/1.1 200 OK
Date: Sat, 10 Dec 2016 13:39:24 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Shift_JIS
P3P: CP=”This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info.”
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=91=vO7aa7YjWxJPGDWffZj–p855KgcdJdpvH9dCUAVgWBX7f8JZdeweK_wY3msj09u8Osyz2tK4H4X3cjnZX1QK45cCxRB910amTq7Kmllk6TS3iH9HMIVw73LAaOW4Swq; expires=Sun, 11-Jun-2017 13:39:24 GMT; path=/; domain=.google.co.jp; HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding

vagrant@vagrant-ubuntu-trusty-64:~$ printf ‘HEAD / HTTP/1.1\r\nHost: www.amazon.com\r\n\r\n’ | nc www.amazon.com 80
HTTP/1.1 301 Moved Permanently
Date: Sat, 10 Dec 2016 13:44:34 GMT
Server: Server
Location: https://www.amazon.com/
Content-Type: text/html; charset=iso-8859-1

vagrant@vagrant-ubuntu-trusty-64:~$ man nc

connecting by nc command.

vagrant@vagrant-ubuntu-trusty-64:~$ nc localhost 3456
vagrant@vagrant-ubuntu-trusty-64:~$ nc -l 3456

getting started Ubuntu

After install vitrualbox and vagrant,

vagrant init ubuntu/trusty64
vagrant up
vagrant ssh
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install netcat-openbsd tcpdump traceroute mtr

command

vagrant@vagrant-ubuntu-trusty-64:~$ ip addr show eth0
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:6c:cb:39 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe6c:cb39/64 scope link
       valid_lft forever preferred_lft forever

vagrant@vagrant-ubuntu-trusty-64:~$ ip route show
default via 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0  proto kernel  scope link  src 10.0.2.15

vagrant@vagrant-ubuntu-trusty-64:~$ ping -c3 8.8.8.8

vagrant@vagrant-ubuntu-trusty-64:~$ host -t aaaa google.com
google.com has IPv6 address 2404:6800:4004:817::200e

vagrant@vagrant-ubuntu-trusty-64:~$ printf 'HEAD / HTTP/1.1\r\nHost: www.udacity.com \r\n\r\n' \ |nc www.udacit.com 80
HTTP/1.1 200 OK
Content-Length: 0
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Sat, 10 Dec 2016 13:16:14 GMT

vagrant@vagrant-ubuntu-trusty-64:~$ sudo tcpdump -n -c5 -i eth0

vagrant@vagrant-ubuntu-trusty-64:~$ mtr www.udacity.com

ping request do not need server, just confirm computer system existing. Ping is simpler than HTTP, http is not ping.

アプリケーション起動時にイベント送信

func application(application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // ...
    let mobileAnalytics =
    AWSMobileAnalytics(forAppId: "ApplicationID")
    let eventClient = mobileAnalytics.eventClient
    let event = eventClient.createEventWithEventType("ApplicationStart")
    eventClient.recordEvent(event)
    eventClient.submitEvent()
    return true
}

プッシュ通知

func push(){
    let publishInput = AWSSNSPublishInput()
    publishInput.targetArn = "arn:aws:sns:us-east-1:xxxxxxxxxx:share-users"
    publishInput.message = "new picture is posted"
    AWSSNS.defaultSNS().publish(publishInput)
}