Skip to content

Commit 31766a2

Browse files
committed
Test HTTP
1 parent 47e9a72 commit 31766a2

File tree

7 files changed

+11948
-9978
lines changed

7 files changed

+11948
-9978
lines changed

Check/HTTP/Client

17 KB
Binary file not shown.

Check/HTTP/client.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include<arpa/inet.h>
4+
#include<netdb.h>
5+
#include<sys/socket.h>
6+
#include<sys/types.h>
7+
#include<unistd.h>
8+
#include<fcntl.h>
9+
#include<sys/stat.h>
10+
#include<string.h>
11+
12+
typedef struct addrinfo AddrInfo;
13+
14+
int get_perm(){
15+
mode_t curr_mask = umask(022);
16+
umask(curr_mask);
17+
return 0666-curr_mask;
18+
}
19+
20+
void main(){
21+
AddrInfo *filter = (AddrInfo*)malloc(sizeof(AddrInfo));
22+
filter->ai_family = AF_UNSPEC;
23+
filter->ai_socktype = SOCK_STREAM;
24+
25+
AddrInfo *serv_addr = (AddrInfo*)malloc(sizeof(AddrInfo));
26+
getaddrinfo("www.africau.edu", "80", filter, &serv_addr);
27+
28+
int sock_fd = socket(serv_addr->ai_family, serv_addr->ai_socktype, serv_addr->ai_protocol);
29+
int retval = connect(sock_fd, serv_addr->ai_addr, serv_addr->ai_addrlen);
30+
if(retval==0){
31+
printf("\nConnected\n");
32+
}
33+
34+
char *request_head = (char*)malloc(sizeof(char)*1000);
35+
sprintf(request_head, "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", "/images/default/sample.pdf", "www.africau.edu");
36+
37+
int size = send(sock_fd, request_head, strlen(request_head), 0);
38+
printf("Sent %d\n", size);
39+
printf("\n%s\n", request_head);
40+
41+
char *response = (char*)malloc(sizeof(char)*1000);
42+
int read_size = -1;
43+
44+
int op_file = open("test.pdf", O_CREAT|O_WRONLY, get_perm());
45+
do{
46+
read_size = recv(sock_fd, response, 100, 0);
47+
printf("\n%s", response);
48+
fflush(stdout);
49+
write(op_file, response, read_size);
50+
}while(read_size!=0);
51+
close(op_file);
52+
53+
54+
}

Check/HTTP/test.html

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
HTTP/1.1 403 Forbidden
2+
X-Frame-Options: SAMEORIGIN
3+
X-XSS-Protection: 1; mode=block
4+
X-Content-Type-Options: nosniff
5+
Content-Security-Policy: frame-ancestors
6+
Content-Type: text/html; charset="utf-8"
7+
Content-Length: 2577
8+
Connection: Close
9+
10+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11+
<html>
12+
<head>
13+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
14+
<meta name="referrer" content="no-referrer">
15+
<title>Web Filter Violation</title>
16+
<style type="text/css">
17+
html, body { margin: 0; padding: 0; font-family: Verdana, Arial, sans-serif; font-size: 10pt; }
18+
h1, h2 { height: 82px; text-indent: -999em; margin: 0; padding: 0; margin: 0; }
19+
div { margin: 0; padding: 0; }
20+
div.header { background: url(http://url.fortinet.net:8008/XX/YY/ZZ/CI/MGPGHGPGPFGHCDPFGGOGFGEH) 0 0 repeat-x; height: 82px; }
21+
div.header h1 { background: url(http://url.fortinet.net:8008/XX/YY/ZZ/CI/MGPGHGPGPFGHCDPFGGHGFHBGCHEGPFHHGG) 0 0 no-repeat; }
22+
div.header h2 { background: url(http://url.fortinet.net:8008/XX/YY/ZZ/CI/MGPGHGPGPFGHCDPFGGOGFGEH) 0 -82px no-repeat; width: 160px; float: right; }
23+
div.sidebar { width: 195px; height: 200px; float: left; }
24+
div.main { padding: 5px; margin-left: 195px; }
25+
div.buttons { margin-top: 30px; text-align: right; }
26+
h3 { margin: 36px 0; font-size: 16pt; }
27+
.blocked h3 { color: #c00; }
28+
.authenticate h3 { color: #36c; }
29+
h2.fgd_icon { background: url(http://url.fortinet.net:8008/XX/YY/ZZ/CI/MGPGHGPGPFGHCDPFGGOGFGEH) 0 -166px repeat-x; width: 90px; height: 92px; margin: 48px auto; }
30+
.blocked h2.fgd_icon { background-position: 0 -166px; }
31+
.authenticate h2.fgd_icon { background-position: -89px -166px; }
32+
form { width: 300px; margin: 30px 0; }
33+
label { display: block; width: 300px; margin: 5px 0; line-height: 25px; }
34+
label input { width: 200px; border: 1px solid #7f9db9; height: 20px; float: right; }
35+
</style>
36+
</head>
37+
<body class="blocked">
38+
<div class="header">
39+
<h2>Powered By Fortinet</h2>
40+
<h1>FortiGuard Web Filtering</h1>
41+
</div>
42+
<div class="sidebar">
43+
<h2 class="fgd_icon">blocked</h2>
44+
</div>
45+
<div class="main">
46+
<h3>Web Page Blocked!</h3>
47+
<div class="notice">
48+
<p>You have tried to access a web page which is in violation of your internet usage policy.</p>
49+
<p>
50+
URL: http://(now/<br />
51+
Category: Newly Observed Domain
52+
<br/>User name:
53+
<br/>Group name:
54+
</p>
55+
<p>
56+
57+
</p>
58+
<p> To have the rating of this web page re-evaluated <a href="http://url.fortinet.net/rate/submit.php?id=0442336B1C28094022652032357A7A6B&cat=5A&loc=http://%28now%2f&ver=8">please click here</a>.</p>
59+
</div>
60+
</div>
61+
</body>
62+
</html>

Check/HTTP/test.pdf

3.77 KB
Binary file not shown.

Check/NAM/udp.tcl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set ns [new Simulator]
2+
$ns rtproto DV
3+
4+
main

Ex7-WebpageDownload/Program/temp

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
HTTP/1.1 200 OK
2+
Date: Mon, 28 Feb 2022 05:23:59 GMT
3+
Content-Type: application/pdf
4+
Content-Length: 3028
5+
Connection: close
6+
Last-Modified: Fri, 24 Feb 2017 17:42:38 GMT
7+
ETag: "58b0708e-bd4"
8+
Expires: Thu, 16 Feb 2023 14:19:31 GMT
9+
Cache-Control: max-age=31536000
10+
Host-Header: 8441280b0c35cbc1147f8ba998a563a7
11+
X-Proxy-Cache-Info: DT:1
12+
CF-Cache-Status: HIT
13+
Age: 1004667
14+
Accept-Ranges: bytes
15+
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=TEfXMIxL%2FzhnfD%2FCSb7EXioe2%2B9GhPwYTuysn7stfQBpJZklAK86LFknVwX2NkkC1Nw59%2B9IP5e1OGspSlqfRB%2FXoDyDzIPN7XeIDb0Jau76dcGGxq3KDcK0Y6bMA1BdVyU%3D"}],"group":"cf-nel","max_age":604800}
16+
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
17+
Server: cloudflare
18+
CF-RAY: 6e47395a9a289379-MAA
19+
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
20+
21+
%PDF-1.3
22+
%����
23+
24+
1 0 obj
25+
<<
26+
/Type /Catalog
27+
/Outlines 2 0 R
28+
/Pages 3 0 R
29+
>>
30+
endobj
31+
32+
2 0 obj
33+
<<
34+
/Type /Outlines
35+
/Count 0
36+
>>
37+
endobj
38+
39+
3 0 obj
40+
<<
41+
/Type /Pages
42+
/Count 2
43+
/Kids [ 4 0 R 6 0 R ]
44+
>>
45+
endobj
46+
47+
4 0 obj
48+
<<
49+
/Type /Page
50+
/Parent 3 0 R
51+
/Resources <<
52+
/Font <<
53+
/F1 9 0 R
54+
>>
55+
/ProcSet 8 0 R
56+
>>
57+
/MediaBox [0 0 612.0000 792.0000]
58+
/Contents 5 0 R
59+
>>
60+
endobj
61+
62+
5 0 obj
63+
<< /Length 1074 >>
64+
stream
65+
2 J
66+
BT
67+
0 0 0 rg
68+
/F1 0027 Tf
69+
57.3750 722.2800 Td
70+
( A Simple PDF File ) Tj
71+
ET
72+
BT
73+
/F1 0010 Tf
74+
69.2500 688.6080 Td
75+
( This is a small demonstration .pdf file - ) Tj
76+
ET
77+
BT
78+
/F1 0010 Tf
79+
69.2500 664.7040 Td
80+
( just for use in the Virtual Mechanics tutorials. More text. And more ) Tj
81+
ET
82+
BT
83+
/F1 0010 Tf
84+
69.2500 652.7520 Td
85+
( text. And more text. And more text. And more text. ) Tj
86+
ET
87+
BT
88+
/F1 0010 Tf
89+
69.2500 628.8480 Td
90+
( And more text. And more text. And more text. And more text. And more ) Tj
91+
ET
92+
BT
93+
/F1 0010 Tf
94+
69.2500 616.8960 Td
95+
( text. And more text. Boring, zzzzz. And more text. And more text. And ) Tj
96+
ET
97+
BT
98+
/F1 0010 Tf
99+
69.2500 604.9440 Td
100+
( more text. And more text. And more text. And more text. And more text. ) Tj
101+
ET
102+
BT
103+
/F1 0010 Tf
104+
69.2500 592.9920 Td
105+
( And more text. And more text. ) Tj
106+
ET
107+
BT
108+
/F1 0010 Tf
109+
69.2500 569.0880 Td
110+
( And more text. And more text. And more text. And more text. And more ) Tj
111+
ET
112+
BT
113+
/F1 0010 Tf
114+
69.2500 557.1360 Td
115+
( text. And more text. And more text. Even more. Continued on page 2 ...) Tj
116+
ET
117+
endstream
118+
endobj
119+
120+
6 0 obj
121+
<<
122+
/Type /Page
123+
/Parent 3 0 R
124+
/Resources <<
125+
/Font <<
126+
/F1 9 0 R
127+
>>
128+
/ProcSet 8 0 R
129+
>>
130+
/MediaBox [0 0 612.0000 792.0000]
131+
/Contents 7 0 R
132+
>>
133+
endobj
134+
135+
7 0 obj
136+
<< /Length 676 >>
137+
stream
138+
2 J
139+
BT
140+
0 0 0 rg
141+
/F1 0027 Tf
142+
57.3750 722.2800 Td
143+
( Simple PDF File 2 ) Tj
144+
ET
145+
BT
146+
/F1 0010 Tf
147+
69.2500 688.6080 Td
148+
( ...continued from page 1. Yet more text. And more text. And more text. ) Tj
149+
ET
150+
BT
151+
/F1 0010 Tf
152+
69.2500 676.6560 Td
153+
( And more text. And more text. And more text. And more text. And more ) Tj
154+
ET
155+
BT
156+
/F1 0010 Tf
157+
69.2500 664.7040 Td
158+
( text. Oh, how boring typing this stuff. But not as boring as watching ) Tj
159+
ET
160+
BT
161+
/F1 0010 Tf
162+
69.2500 652.7520 Td
163+
( paint dry. And more text. And more text. And more text. And more text. ) Tj
164+
ET
165+
BT
166+
/F1 0010 Tf
167+
69.2500 640.8000 Td
168+
( Boring. More, a little more text. The end, and just as well. ) Tj
169+
ET
170+
endstream
171+
endobj
172+
173+
8 0 obj
174+
[/PDF /Text]
175+
endobj
176+
177+
9 0 obj
178+
<<
179+
/Type /Font
180+
/Subtype /Type1
181+
/Name /F1
182+
/BaseFont /Helvetica
183+
/Encoding /WinAnsiEncoding
184+
>>
185+
endobj
186+
187+
10 0 obj
188+
<<
189+
/Creator (Rave \(http://www.nevrona.com/rave\))
190+
/Producer (Nevrona Designs)
191+
/CreationDate (D:20060301072826)
192+
>>
193+
endobj
194+
195+
xref
196+
0 11
197+
0000000000 65535 f
198+
0000000019 00000 n
199+
0000000093 00000 n
200+
0000000147 00000 n
201+
0000000222 00000 n
202+
0000000390 00000 n
203+
0000001522 00000 n
204+
0000001690 00000 n
205+
0000002423 00000 n
206+
0000002456 00000 n
207+
0000002574 00000 n
208+
209+
trailer
210+
<<
211+
/Size 11
212+
/Root 1 0 R
213+
/Info 10 0 R
214+
>>
215+
216+
startxref
217+
2714
218+
%%EOF

0 commit comments

Comments
 (0)