Skip to content

Instantly share code, notes, and snippets.

@paul-jean
Created June 15, 2014 02:25
Show Gist options
  • Select an option

  • Save paul-jean/ff56e7598491dcc41b9d to your computer and use it in GitHub Desktop.

Select an option

Save paul-jean/ff56e7598491dcc41b9d to your computer and use it in GitHub Desktop.
awk script to extract header from HTML response
echo -e "GET / HTTP/1.0\r\n\r\n" | nc google.com 80 | awk '{a[NR]=$0} END {line=1; while (length(a[line]) > 1) {print a[line]; line += 1} }'
@paul-jean
Copy link
Copy Markdown
Author

Output:

[rule146@rule146: Desktop]$ echo -e "GET / HTTP/1.0\r\n\r\n" | nc google.com 80 | awk '{a[NR]=$0} END {line=1; while (length(a[line]) > 1) {print a[line]; line += 1} }'
HTTP/1.0 200 OK
Date: Sun, 15 Jun 2014 02:24:17 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=497e10387b05f153:FF=0:TM=1402799057:LM=1402799057:S=1dyf_izwNXQsSaRC; expires=Tue, 14-Jun-2016 02:24:17 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=FRhcszGWYfIRvKLRXoKdMrdYGVU2RVO7SwZ7jdejJkB2KwSvPhbiIgYA7kbu1rg7TitI07ERuZC1ppmctq6r7XUpzyjHJWn5HRRfLHeXPAVxbFGLpFc0ildlNDlZxd_U; expires=Mon, 15-Dec-2014 02:24:17 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic

@paul-jean
Copy link
Copy Markdown
Author

That's like the hardest way to extract the header from the HTTP response. The easy way is just to issue a HEAD request:

[rule146@rule146: Desktop]$ echo -e "HEAD / HTTP/1.0\r\n\r\n" | nc google.com 80
HTTP/1.0 200 OK
Date: Sun, 15 Jun 2014 02:27:47 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=673824b89046c664:FF=0:TM=1402799267:LM=1402799267:S=VZqMn8MbQeemH-mO; expires=Tue, 14-Jun-2016 02:27:47 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=vhcwH0OamVac7AneZE-WPKPC81oUdcyTZTF78uxDXyBiXcC2-aIj-qV9uCE_FFkQ7Ky6zHOovT_ZedZqBypgT9QMddXm-TzibyRezR08Fb94WuA5PkIO7mXAGK7YJHxr; expires=Mon, 15-Dec-2014 02:27:47 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment