13. 8. 10.

안드로이드 C#.NET PUSH 서버

push.aspx 파일
1
2
3
4
5
6
7
8
9
10
11
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="push.aspx.cs" Inherits="mobile_push" %>
 
<!DOCTYPE html>
<html>
<head>
    <title>푸쉬 전송 TEST</title>
</head>
<body>
<asp:Literal ID="SendResult" runat="server" />
</body>
</html>


push.aspx.cs 파일
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Net.Security;
using System.Net;
using System.Text;
using System.IO;
using System.Security.Cryptography.X509Certificates;
 
public partial class mobile_push : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
 
 
        // 브라우저APIkey
        string BrowserAPIKey = Request.QueryString["ApiKey"];
        // BrowserAPIKey  = "AIzaSyBi0pn1ckaJhRL9kK3mbwsHzk7x0fdE_Z8";
 
        // regId(받을사람이 지급받은 registration_ids - 여러명일 경우 배열로 받아처리하면 될 듯 최대 1000)
        string RegId = Request.QueryString["RegId"];
        // RegId = "APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9po8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR";
 
        // 알림명
        string tickerText = Request.QueryString["Ticker"];
        // tickerText = "알림테스트";
 
        // 알림 제목
        string contentTitle = Request.QueryString["Title"];
        // contentTitle = "알림제목";
 
        // 알림 내용
        string message = Request.QueryString["Msg"];
        // message = "안녕하세요~~~푸쉬입니다.";
 
        string postData = "";
        postData += "{";
        postData += "  \"registration_ids\": [ \"" + RegId + "\" ]";
        postData += ", \"data\": {";
        postData += "                 \"tickerText\":\"" + tickerText + "\"";
        postData += "               , \"contentTitle\":\"" + contentTitle + "\"";
        postData += "               , \"message\": \"" + message + "\"";
        postData += "            }";
        postData += "}";
 
        string response = SendGCMNotification(BrowserAPIKey, postData);
 
        SendResult.Text = response;
 
    }
 
 
 
    private string SendGCMNotification(string apiKey, string postData, string postDataContentType = "application/json")
    {
        ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);
        //  MESSAGE CONTENT
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        //  CREATE REQUEST
        HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
        Request.Method = "POST";
        Request.KeepAlive = false;
        Request.ContentType = postDataContentType;
        Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
        Request.ContentLength = byteArray.Length;
 
        Stream dataStream = Request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
 
        //  SEND MESSAGE
        try
        {
            WebResponse Response = Request.GetResponse();
            HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
            if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
            {
                var text = "Unauthorized - need new token";
                Console.Write(text);
            }
            else if (!ResponseCode.Equals(HttpStatusCode.OK))
            {
                var text = "Response from web service isn't OK";
                Console.Write(text);
            }
 
            StreamReader Reader = new StreamReader(Response.GetResponseStream());
            string responseLine = Reader.ReadToEnd();
            Reader.Close();
 
            return responseLine;
        }
        catch (Exception e)
        {
 
        }
        return "Error";
 
    }
 
    public static bool ValidateServerCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }
}

13. 7. 19.

Javascript 브라우저 기본정보 체크

1
2
3
4
5
6
7
8
9
window.onload = function(){
 var html="";
 html += "width : " + "<strong>" + screen.availWidth + "</strong>";
 html += "height : " + "<strong>" + screen.availHeight + "</strong>";
 html += "platform : " + "<strong>" + navigator.platform + "</strong>";
 html += "app_name : " + "<strong>" + navigator.appName + "</strong>";
 html += "app_version : " + "<strong>" + navigator.appVersion + "</strong>";
 document.write(html);
}

13. 6. 14.

C++(Windows) TCP 클라이언트

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
 
#pragma comment(lib,"wsock32.lib")
 
#define PORT 2020
#define CONN_IP "127.0.0.1"
 
int main(void){
 
 // WSAStartup
 
 // 소켓버전을 받음
 WSADATA wsaData;
  
 if(WSAStartup(WINSOCK_VERSION, &wsaData) != 0 ){
  printf("WSAStartup 실패, 에러코드 = %u\n",WSAGetLastError());
  return false;
 }else{
  printf("WSAStartup 성공\n");
 }
 
 
 // socket
 
 // 소켓디스크립터
 SOCKET s;
 
 // TCP/IP용 소켓생성
 s=socket(AF_INET,SOCK_STREAM,0);
 if(s==INVALID_SOCKET){
  printf("소켓 생성 실패, 에러코드 : %u\n",WSAGetLastError());
  WSACleanup();
  return false;
 }else{
  printf("소켓 생성 성공\n");
 }
  
 
 // setsockopt (SO_RCVBUF)
 
 // 1Mbytes 의 수신버퍼
 int nBufLen = 1048576;
 // 옵션 변수의 길이
 int size =sizeof(int);
  
 if( setsockopt(s, SOL_SOCKET,SO_RCVBUF, (char*)&nBufLen, size) != 0){
  printf("소켓 수신 버퍼 크기 설정 실패, 에러코드 = %u\n",WSAGetLastError());
  //소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("소켓 수신 버퍼 크기 설정 성공\n");
 }
 
 //* 바인드는 필요에 따라 사용
 // bind
 SOCKADDR_IN addr_bind;
  
 // AF_INET 체계임을 명시
 addr_bind.sin_family = AF_INET;
 // 설정된 포트를 사용
 addr_bind.sin_port = htons(PORT+1);
 // 기본네트워크 카드 설정
 addr_bind.sin_addr.s_addr = htonl(ADDR_ANY);
 
 if( bind(s, (LPSOCKADDR)&addr_bind, sizeof(addr_bind)) == SOCKET_ERROR){
  printf("바인드 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("바인드 성공\n");
 }
 //*/
 
 
 // connect
 
 // 소켓 구조체
 SOCKADDR_IN serv_addr;
 
 // 주소 체계 설정
 serv_addr.sin_family = AF_INET;
 // 설정된 포트를 사용
 serv_addr.sin_port = htons(PORT);
 // 접속주소 설정
 serv_addr.sin_addr.s_addr = inet_addr(CONN_IP);
 
 printf("접속 중...\n");
 
 if( connect(s, (SOCKADDR*)&serv_addr, sizeof(serv_addr)) == SOCKET_ERROR){
  printf("접속 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("접속 성공\n");
 }
 
 printf("접속 완료!!!\n");
 
 
 // getsockname
 SOCKADDR_IN cli_addr;
 
 size = sizeof SOCKADDR_IN;
 
 if( getsockname(s, (LPSOCKADDR)&cli_addr, &size) == SOCKET_ERROR){
  printf("로컬 정보 얻기 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("로컬 정보 얻기 성공\n");
 }
 
 printf("로컬 접속 IP : %s, 포트 : %d\n",inet_ntoa(cli_addr.sin_addr),ntohs(cli_addr.sin_port));
 
 
  // send
 
 char buf[8] = "Hello";
 int len = 5;
 int ret;
 
 ret = send(s,buf,len,0);
 if(ret == SOCKET_ERROR){
  printf("데이터 송신 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
 
 // recv
 
 ret = recv(s,buf,len,0);
 if(ret == SOCKET_ERROR){
  printf("소켓 통신 오류 발생, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
  
 printf("수신 데이터 = %s (%d bytes)\n",buf,ret);
 
 
 // shutdown
  
 if(shutdown(s, SD_BOTH) != 0){
  printf("안전 종료 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("안전 종료 성공\n");
 }
 
 
 if(closesocket(s) != 0){
  printf("소켓 제거 실패, 에러코드 = %u\n",WSAGetLastError());
  WSACleanup();
  return false;
 }else{
  printf("소켓 제거 성공\n");
 }
  
 
 // WSACleanup
  
 if(WSACleanup() != 0){
  printf("WSACleanup 실패, 에러코드 = %u\n",WSAGetLastError());
  return false;
 }else{
  printf("WSACleanup 성공\n");
 }
 
 return true;
}

13. 6. 13.

C++(Windows) TCP 서버

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
 
#pragma comment(lib,"wsock32.lib")
 
#define PORT 2020
 
int main(void){
 
 // WSAStartup
  
 // 소켓버전을 받음
 WSADATA wsaData;
 
 if(WSAStartup(WINSOCK_VERSION, &wsaData) != 0 ){
  printf("WSAStartup 실패, 에러코드 = %u\n",WSAGetLastError());
  return false;
 }else{
  printf("WSAStartup 성공\n");
 }
 
 
 // socket
 
 // 소켓디스크립터
 SOCKET s;
 
 // TCP/IP용 소켓생성
 s=socket(AF_INET,SOCK_STREAM,0);
 
 if(s==INVALID_SOCKET){
  printf("소켓 생성 실패, 에러코드 : %u\n",WSAGetLastError());
  WSACleanup();
  return false;
 }else{
  printf("소켓 생성 성공\n");
 }
 
 
 // setsockopt (SO_RCVBUF)
 
 // 1Mbytes 의 수신버퍼
 int nBufLen = 1048576;
 // 옵션 변수의 길이
 int size =sizeof(int);
 
 if( setsockopt(s, SOL_SOCKET,SO_RCVBUF, (char*)&nBufLen, size) != 0){
  printf("소켓 수신 버퍼 크기 설정 실패, 에러코드 = %u\n",WSAGetLastError());
  //소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("소켓 수신 버퍼 크기 설정 성공\n");
 }
 
 
 // bind
 
 SOCKADDR_IN addr_bind;
  
 // AF_INET 체계임을 명시
 addr_bind.sin_family = AF_INET;
 // 설정된 포트를 사용
 addr_bind.sin_port = htons(PORT);
 // 기본네트워크 카드 설정
 addr_bind.sin_addr.s_addr = htons(ADDR_ANY);
 
 if( bind(s, (LPSOCKADDR)&addr_bind, sizeof(addr_bind)) == SOCKET_ERROR){
  printf("바인드 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("바인드 성공\n");
 }
 
 
 // listen
 
 if( listen(s, SOMAXCONN) == SOCKET_ERROR){
  printf("접속 대기 큐 설정 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("접속 대기 큐 설정 성공\n");
 }
 
 
 // accept
 
 struct sockaddr_in cli_addr;
 size = sizeof(cli_addr);
 
 printf("수신 대기 중...\n");
 
 SOCKET cs = accept(s,(sockaddr*)&cli_addr,&size);
 
 if(cs==INVALID_SOCKET){
  printf("접속 승인 실패, 에러코드 = %u\n",WSAGetLastError());
  // 소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("접속 승인 성공\n");
 }
 
 printf("클라이언트 접속 ! \n클라이언트 IP : %s, 포트 : %d\n",inet_ntoa(cli_addr.sin_addr),ntohs(cli_addr.sin_port));
 
 
 // getpeername
 
 if( getpeername(s, (LPSOCKADDR)&cli_addr, &size) == SOCKET_ERROR){
  printf("클라이언트 정보 얻기 실패, 에러코드 = %u\n",WSAGetLastError());
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("클라이언트 정보 얻기 성공\n");
 }
 
 printf("클라이언트 IP : %s, 포트 : %d\n",inet_ntoa(cli_addr.sin_addr),ntohs(cli_addr.sin_port));
 
 
 // select
 
 FD_SET fd = {1,cs};
 // 타임아웃 3초 {3,0}
 TIMEVAL tv = {3,0};
 
 int ret;
 
 ret = select(0,&fd,NULL,NULL,&tv);
 
 if(ret == 0){
  printf("3초 동안 버퍼에 수신된 패킷이 없습니다.\n");
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
 
 if(ret == SOCKET_ERROR){
  printf("소켓 통신 오류 발생, 에러코드 = %u\n",WSAGetLastError());
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
 
 
 // recv
 
 char buf[10] = {0,};
 int len = 5;
 
 ret = recv(cs,buf,len,0);
 if(ret == SOCKET_ERROR){
  printf("소켓 통신 오류 발생, 에러코드 = %u\n",WSAGetLastError());
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
 
 printf("수신 데이터 = %s (%d bytes)\n",buf,ret);
 
 
 // send
 
 ret = recv(cs,buf,len,0);
 if(ret == SOCKET_ERROR){
  printf("데이터 송신 실패, 에러코드 = %u\n",WSAGetLastError());
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }
 
 
 // shutdown
 
 if(shutdown(cs, SD_BOTH) != 0){
  printf("안전 종료 실패, 에러코드 = %u\n",WSAGetLastError());
  // 클라이언트 접속 소켓 제거
  closesocket(cs);
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("안전 종료 성공\n");
 }
  
 
 // closesocket
 
 if(closesocket(cs) != 0){
  printf("소켓 제거 실패, 에러코드 = %u\n",WSAGetLastError());
  // 대기소켓제거
  closesocket(s);
  WSACleanup();
  return false;
 }else{
  printf("소켓 제거 성공\n");
 }
 
 if(closesocket(s) != 0){
  printf("소켓 제거 실패, 에러코드 = %u\n",WSAGetLastError());
  WSACleanup();
  return false;
 }else{
  printf("소켓 제거 성공\n");
 }
 
 
 // WSACleanup
 if(WSACleanup() != 0){
  printf("WSACleanup 실패, 에러코드 = %u\n",WSAGetLastError());
  return false;
 }else{
  printf("WSACleanup 성공\n");
 }
 
 
 return true;
}

13. 5. 29.

C# DNS로 아이피 알아내기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Net;
 
namespace cShapNslookup
{
    class Program
    {
        static void Main(string[] args)
        {
            string HostName = "";
             
            HostName = "www.naver.com";
            //실제 name 을 가져오기 위해 IPHostEntry을 이용
 
            IPHostEntry hostEntry = Dns.GetHostByName(HostName);
            Console.WriteLine("실제이름 : " + hostEntry.HostName + "");
            //IP 주소를 찾아서 출력함
 
            foreach (IPAddress ip in hostEntry.AddressList)
            {
                Console.WriteLine(ip.ToString());
            }
 
        }
    }
}

13. 5. 21.

Classic ASP Email 전송

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<%
     
' Mail 발송
Function eMailCDOSend(MailTitle, MailTag, Sender, Receiver)
 ' MailTitle : 제목
 ' MailTag : html내용
 ' Sender : 보내는 사람
 ' Receiver : 받는사람
 ' 2008서버 이상 에서 발송하는 환경정보 설정
 Dim eMailObject, eMailConfig
 Set eMailObject = Server.CreateObject("CDO.Message")
 Set eMailConfig = Server.CreateObject("CDO.Configuration")
 Dim SchemaPath : SchemaPath = "http://schemas.microsoft.com/cdo/configuration/"
 With eMailConfig.Fields
  .Item (SchemaPath & "sendusing") = 2  'CDOSendUsingPort
  .Item (SchemaPath & "smtpserver") = "127.0.0.1"  'CDOSendUsingPort [ServerIP]
  .Item (SchemaPath & "smtpserver") = "localhost"    'CDOSendUsingPort
  .Item (SchemaPath & "smtpserverport") = "25"  'Port
  .Update
 End With
 eMailObject.Configuration = eMailConfig
 Set eMailConfig = Nothing
 With eMailObject
  .From = Sender
  .To = Receiver
  .Subject = MailTitle
  .HTMLBody = MailTag
'  .HTMLBodyPart.Charset = "Utf-8"
  .Send
 End With
 Set eMailObject = Nothing
End Function
 
 
%>

Class ASP 에서 사이트 소스 긁어오기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<%
'페이지로드Post방식
Function getSiteSourcePost( siteURL, params )
 Set httpObj = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
 httpObj.open "POST" , siteURL, False
 httpObj.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 '포스트 방식시 위의 라인을 추가해 주어야 한다.
  
 httpObj.Send params
 '포스트의 파라미터는 Send 호출시 같이 값을 넘겨 주어야 한다.
 httpObj.WaitForResponse
 If httpObj.Status = "200" Then
  getSiteSourcePost = httpObj.ResponseText
 Else
  getSiteSourcePost = null
 End If
End Function
 
'페이지로드 get방식
Function getSiteSourceGet( siteURL, params )
 Set httpObj = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
 httpObj.open "GET", siteURL & "?" & params, False
  
 httpObj.Send()
 httpObj.WaitForResponse
 If httpObj.Status = "200" Then
  getSiteSourceGet = httpObj.ResponseText
 Else
  getSiteSourceGet = null
 End If
End Function
 
'네이버
response.write(getSiteSourcePost("http://www.naver.com",""))
 
'다음
response.write(getSiteSourcePost("http://www.daum.net",""))
%>

Classic ASP HTML 태그 제거

1
2
3
4
5
6
7
8
9
10
11
12
'태그제거
function StripTags( htmlDoc )
  dim rex
  set rex = new Regexp
  rex.Pattern= "<[^>]+>"
  rex.Global=true
  StripTags =rex.Replace(htmlDoc,"")
end function
 
html = "<a href=""http://2nusa.blogspot.kr/""><b>Hello My World</b></a>"
 
response.write(StripTags(html ))

MS-SQL 테이블 정보 얻는 쿼리(테이블스키마)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT
 A.TABLE_NAME,
 C.VALUE AS TABLE_COMMENT,
 A.COLUMN_NAME,
 A.DATA_TYPE,
 ISNULL(CAST(A.CHARACTER_MAXIMUM_LENGTH AS VARCHAR), 
 CAST(A.NUMERIC_PRECISION AS VARCHAR) + ',' + CAST(A.NUMERIC_SCALE AS VARCHAR)) AS COLUMN_LENGTH,
 A.COLUMN_DEFAULT, A.IS_NULLABLE,
 B.VALUE AS COLUM_COMMENT
FROM
 INFORMATION_SCHEMA.COLUMNS A
 LEFT OUTER JOIN
 SYS.EXTENDED_PROPERTIES B
  ON B.major_id = object_id(A.TABLE_NAME)
  AND A.ORDINAL_POSITION = B.minor_id
 LEFT OUTER JOIN
  (SELECT object_id(objname) AS TABLE_ID,
  VALUE
  FROM ::FN_LISTEXTENDEDPROPERTY
  (NULL, 'User','dbo','table',NULL, NULL, NULL)) C
  ON object_id(A.TABLE_NAME) = C.TABLE_ID
WHERE A.TABLE_NAME = '테이블명'
ORDER BY A.TABLE_NAME, A.ORDINAL_POSITION

13. 5. 15.

MS-SQL Database 이동 및 로그용량 관리

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
USE master
 
--sql 목록제거
EXEC sp_detach_db 'DB명', 'true'
 
--C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
--DB파일,DB_log파일 d:\SQL DATA\로 이동
 
--sql 목록추가
EXEC sp_attach_db @dbname = N'DB명',
   @filename1 = N'd:\SQL Data\DB명.mdf',
   @filename2 = N'd:\SQL Data\DB명_log.ldf'
 
--sql 로그용량 줄이기
use DB명
backup log DB명 with no_log
dbcc shrinkfile('DB명_log', 50)
 
-- 트렌젝션 로그사이즈 제한
dbcc shrinkdatabase(db명,1000)
1
2
3
4
5
6
7
8
9
10
-- 로그용량 줄이기
USE [DB명];
GO
ALTER DATABASE DB명
SET RECOVERY SIMPLE;
GO
DBCC SHRINKFILE ('DB명_Log', 10);
GO
ALTER DATABASE DB명
SET RECOVERY FULL;

13. 5. 14.

C# 컴퓨터 재부팅 및 끄기

프로젝트 << 참조 << .NET << System.Management 추가
나머지는 알아서 추가 ㅡ.ㅡ;;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public partial class Form1 : Form
    {
        [DllImport("user32.Dll")]
 
        public static extern int SystemParametersInfo(int uAction, int uparam, string lpvParam, int fuWinIni);
 
        public Form1()
        {
            InitializeComponent();
        }
 
        public enum ShutDown
        {
            LogOff = 0,
            Shutdown = 1,
            Reboot = 2,
            ForcedLogOff = 4,
            ForcedShutdown = 5,
            ForcedReboot = 6,
            PowerOff = 8,
            ForcedPowerOff = 12
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            // 컴퓨터 재시작
            // shutDown(ShutDown.ForcedReboot);
            // 컴퓨터 끄기
            // shutDown(ShutDown.ForcedShutdown);
        }
 
        // 끄기모드
        private void shutDown(ShutDown flag)
        {
            ManagementBaseObject outParam = null;
            ManagementClass sysOS = new ManagementClass("Win32_OperatingSystem");
            sysOS.Get();
            // enables required security privilege.
            sysOS.Scope.Options.EnablePrivileges = true;
            // get our in parameters
            ManagementBaseObject inParams = sysOS.GetMethodParameters("Win32Shutdown");
            // pass the flag of 0 = System Shutdown
            inParams["Flags"] = flag;
            inParams["Reserved"] = "0";
            foreach (ManagementObject manObj in sysOS.GetInstances())
            {
                outParam = manObj.InvokeMethod("Win32Shutdown", inParams, null);
            }
        }
    }

13. 5. 12.

Classic ASP 영상파일 이미지추출

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Set Executor = Server.CreateObject("ASPExec.Execute")
 
fileUrl = "d:\file\abc.avi"
 
if fs.FileExists(fileUrl) then
 VideoimgName = fs.getfilename(fileUrl)
 VideoimgNameArr = split(VideoimgName,".")
 if isArray(VideoimgNameArr) then
  vFileName = "v" & mid(VideoimgNameArr(0),2)
  Executor.Application = "ffmpeg -y -i " & fileUrl & " -vframes 1 -ss 00:00:02 -an -vcodec png -f rawvideo -s 400*300 d:\file\videoimg\" & vFileName & ".png"
  Executor.Parameters = ""
  strResult = Executor.ExecuteDosApp
  vImg = "'/file/videoimg/"& vFileName & ".png'"
 end if
end if

13. 5. 11.

Classic ASP 모바일 체크

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
dim u,b,v
 
set u=Request.ServerVariables("HTTP_USER_AGENT")
set b=new RegExp
set v=new RegExp
 
b.Pattern="android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino"
v.Pattern="1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-"
 
b.IgnoreCase=true
v.IgnoreCase=true
 
b.Global=true
v.Global=true
 
if b.test(u) or v.test(Left(u,4)) then
    Response.Write("모바일페이지입니다.")
end if

Javascript 모바일과 PC 체크하는 법

1
2
3
4
5
6
7
8
9
var UserAgent = navigator.userAgent;
var ConType = "";
// 모바일 체크
if (UserAgent.match(/iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson/i) != null || UserAgent.match(/LG|SAMSUNG|Samsung/) != null){
    ConType = "mobile";
}else{
    ConType = "PC";
}
alert(ConType);

13. 5. 10.

Classic ASP 와 MS-SQL 연동

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<OBJECT RUNAT="server" PROGID=ADODB.Connection id="ObjConn"> </OBJECT>
<%
   dim fs,objFile
   dim ObjSql ,WhereSql ,Rs,i,ListArr
   dim Field0,Field1,,Field2,Field3,Field4
   dim Val1, Val12,Url
   dim intNowPage ,intPageSize ,intBlockPage
 
   Set fs = Server.CreateObject("Scripting.FileSystemObject")
   Set objFile = fs.OpenTextFile("c:\DB_file.dat",1)
   ' c:\DB_file.dat 내용
   ' Provider=SQLOLEDB.1;User ID=sa;Password=1111;Initial Catalog=master;Data Source=123.123.123.123,1433
   ObjConn.open objFile.readline
  
   Val1 = Request.QueryString("Val1")
   Val2 = Request.QueryString("Val2")
  
   If Val1<>"" and Val12<>"" Then
      WhereSql = " WHERE " & Val1 & "='" & Val2 & & "'"
      Url = "&Val1=" & Val1 & "&Val2 =" & Val2
   End If
  
   ObjSql = "SELECT * FROM DB_TABLE" & WhereSql
  
   Set Rs=ObjConn.Execute(ObjSql)
   If Not Rs.Eof Then ListArr = Rs.Getrows ' DB를 ListArr 에 저장
   Rs.Close
   Set Rs=Nothing
  
   intNowPage = Request.QueryString("page"' 현제페이지
   intPageSize = 10    ' 페이지크기
   intBlockPage = 10   ' 페이지묶음크기
  
    If Len(intNowPage) = 0 Then      ' 현제페이지값이없을경우
        intNowPage = 1
    End If
 
    If isArray(ListArr) then               ' 목록이 있을경우 페이지 수
       intTotalCount = Ubound(ListArr,2)+1
       If (intTotalCount Mod intPageSize)=0 Then
          intTotalPage = int(intTotalCount/intPageSize)
       Else
          intTotalPage = int(intTotalCount/intPageSize)+1
       End if
    End if
 
   If isArray(ListArr) Then   '자료 있다면 변수에 저장
     ' 페이지 나눌경우(없을경우 0 To Ubound(ListArr,2))
      For i=0+(intNowPage*intPageSize-intPageSize) to (intNowPage*intPageSize)-1  
        If i<=Ubound(ListArr,2) then
           Field0 = ListArr(0,i)
           Field1 = ListArr(1,i)
           Field2 = ListArr(2,i)
           Field3 = ListArr(3,i)
           Field4 = ListArr(4,i)
        End If
     Next
  
   ' 페이지 나누기
If isArray(ListArr) Then
    intTemp = Int((intNowPage - 1) / intBlockPage) * intBlockPage + 1
  
    If intTemp = 1 Then
     Response.Write("◀")
    Else
     Response.Write("<a href=""?page=" & intTemp - intBlockPage & Url & """>◀</a>")
    End If
  
    intLoop = 1
  
    Do Until intLoop > intBlockPage Or intTemp > intTotalPage
     If intTemp = CInt(intNowPage) Then
      Response.Write("<font size= 3><b>" & intTemp &"</b></font> " )
     Else
      Response.Write("<a href=""?page=" & intTemp &url &""">" & intTemp& "</a> ")
     End If
     intTemp = intTemp + 1
     intLoop = intLoop + 1
    Loop
  
     If intTemp > intTotalPage Then
       Response.Write("▶")
     Else
       Response.Write("<a href=""?page=" & intTemp & Url &  """>▶</a>")
     End If
   End if
%>

2013년 05월 10일 블로그 시작...

이런거 만든적은 없어서 제대로 관리할지는 의문이지만 시작이 반이니 뭐.. 어떻게든 되겠지... 푸하~~