13 December 2011

sudoers command in root user

sudoers command in root user file :
user_group    ALL=(ALL) NOPASSWD: /usr/local/bin/command.sh
#Cmnd_Alias   COMMAND_USER = /usr/local/bin/command.sh
#user_group   ALL=(ALL) NOPASSWD: COMMAND_USER

06 July 2011

ASP.NET Error The conversion of a nvarchar data type to a smalldatetime data type resulted in an out-of-range value.

ASP.NET Error The conversion of a nvarchar data type to a smalldatetime data type resulted in an out-of-range value. Can fix:
userQuizDataSource.InsertParameters.Add(
    "DateTimeComplete",
    TypeCode.DateTime,
    DateTime.Now.ToString()
);

28 March 2011

ReadFile Encoding UTF-8 - java

ReadFile Encoding UTF-8 - java
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadUTF8Data {
    private static final String FILE_ENCODE = "UTF-8";
    public static void main(String[] args) {
        String data = null;
        BufferedReader dataIns = null;
        String file = "";
        try {
            dataIns = new BufferedReader(new InputStreamReader(
            new FileInputStream(file), FILE_ENCODE));
            
            while ((data = dataIns.readLine()) != null) {
                System.out.println("Line 1 :" + data);
            }
            dataIns.close();
            dataIns = null;
            } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

15 March 2011

mysql server เข้าใช้ได้จากเครื่องอื่น

mysql server เข้าใช้ได้จากเครื่องอื่น แก้ไฟล์ /etc/mysql/my.cnf
bind-address  = 127.0.0.1
เป็น
#bind-address  = 127.0.0.1
กำหนดสิทธิ์การเข้าใช้ Database
mysql> GRANT ALL ON DB_NAME.* TO 'USERNAME'@"%" IDENTIFIED BY 'NEW_PASSWORD';

08 March 2011

Turn on Bash Smart Completion

Turn on Bash Smart Completion The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
cd Do[TAB-key]
will automatically yield:
cd Documents
If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed
cd D
you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too. Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!! To enable smart completion, edit your
/etc/bash.bashrc
file. Uncomment the following lines, by removing the # in the beginning of the lines:
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
Now you can use tab completion to power your way through commands. You can even extend bash smart completion to your own favourite commands
by using , the “complete” utility and
Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

25 February 2011

ป้องกันการโดนโจมตีเครื่องเซิร์ฟเวอร์ด้วย iptable

ป้องกันการโดนโจมตีเครื่องเซิร์ฟเวอร์ด้วย iptable IPTABLES เป็น Firewall พื้นฐานของ Linux เกือบทุก Distro และให้ประสิทธิภาพที่สูงมากในการ Filtering Traffic และ การป้องกันการ Attack ต่างๆ โดยที่จะมีตัวอย่างพอสังเขป ดังนี้ เปิดการใช้งาน IP Forward ป้องกัน Syn Flood และ อนุญาติให้มีการใช้งานแบบ Dynamic IP (ต่อเนต DSL ทั่วไป)
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 1 > /proc/sys/net/ipv4/ip_dynaddr
Drop Packet ก่อนหน้านี้ทั้งหมด
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
อนุญาติเฉพาะ SSH, SMTP, DNS, Web Services, SSL และ POP3 ให้ผ่านเข้าออก
iptables -A INPUT -p tcp -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp –dport 22 –syn -j ACCEPT
iptables -A INPUT -p tcp –dport 25 –syn -j ACCEPT
iptables -A INPUT -p tcp –dport 53 –syn -j ACCEPT
iptables -A INPUT -p udp –dport 53 –syn -j ACCEPT
iptables -A INPUT -p tcp –dport 80 –syn -j ACCEPT
iptables -A INPUT -p tcp –dport 443 –syn -j ACCEPT
iptables -A INPUT -p tcp –dport 110 –syn -j ACCEPT
ป้องกันการ scan ports
iptables -N check-flags
iptables -F check-flags
iptables -A check-flags -p tcp –tcp-flags ALL FIN,URG,PSH -m limit –limit 5/minute -j LOG –log-level alert –log-prefix "NMAP:"
iptables -A check-flags -p tcp –tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A check-flags -p tcp –tcp-flags ALL ALL -m limit –limit 5/minute -j LOG –log-level 1 –log-prefix "XMAS:"
iptables -A check-flags -p tcp –tcp-flags ALL ALL -j DROP
iptables -A check-flags -p tcp –tcp-flags ALL SYN,RST,ACK,FIN,URG -m limit –limit 5/minute -j LOG –log-level 1 –log-prefix "XMAS-PSH:"
iptables -A check-flags -p tcp –tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
iptables -A check-flags -p tcp –tcp-flags ALL NONE -m limit –limit 5/minute -j LOG –log-level 1 –log-prefix "NULL_SCAN:"
iptables -A check-flags -p tcp –tcp-flags ALL NONE -j DROP
iptables -A check-flags -p tcp –tcp-flags SYN,RST SYN,RST -m limit –limit 5/minute -j LOG –log-level 5 –log-prefix "SYN/RST:"
iptables -A check-flags -p tcp –tcp-flags SYN,RST SYN,RST -j DROP
iptables -A check-flags -p tcp –tcp-flags SYN,FIN SYN,FIN -m limit –limit 5/minute -j LOG –log-level 5 –log-prefix "SYN/FIN:"
iptables -A check-flags -p tcp –tcp-flags SYN,FIN SYN,FIN -j DROP
ป้องกันการ flood SSH (SSH Brute Force)
iptables -I INPUT -p tcp –dport 22 -i eth0 -m state –state NEW -m recent –set
iptables -I INPUT -p tcp –dport 22 -i eth0 -m state –state NEW -m recent –update –seconds 600 –hitcount 2 -j DROP
ห้าม ping
iptables -A INPUT -p ICMP -i eth0 –icmp-type 8 -j DROP
ห้าม traceroute
iptables -A INPUT -p ICMP -i eth0 –icmp-type 11 -j DROP
Protect Syn Flood
iptables -N syn-flood
iptables -A syn-flood -i eth0 -m limit –limit 75/s –limit-burst 100 -j RETURN
iptables -A syn-flood -j LOG –log-prefix "SYN-FLOOD: "
iptables -A syn-flood -j DROP
REDIRECT PORT 10080 to 80 (192.168.xxx.xxx = ip ของเรา)
iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j DNAT –to 192.168.xxx.xxx:10080
iptables -A FORWARD -p tcp -i eth0 -d 192.168.xxx.xxx –dport 80 -j ACCEPT
iptables -A FORWARD -p tcp -i eth0 -d 192.168.xxx.xxx –sport 80 -j ACCEPT
Transparent Proxy
iptables -t nat -A PREROUTING -p TCP –dport 80 -j REDIRECT -to-ports 3128

14 February 2011

DNS Thailand

DNS Thailand Dns in thailand and other
#true-old
203.144.255.71
203.144.255.72

#true-new
203.144.207.29
203.144.207.49
 
#A-net
Primary Domain Name Server (DNS) : 203.148.255.70
Secondary Domain Name Server (DNS) : 203.148.255.80

#Asia Access
Primary Domain Name Server (DNS) : 203.145.0.1
Secondary Domain Name Server (DNS) : 203.145.0.2

#Asia Infonet
Primary Domain Name Server (DNS) : 203.144.255.71
Secondary Domain Name Server (DNS) : 203.144.255.72

#Assumption University ABAC
Primary Domain Name Server (DNS) : 202.6.100.1
Secondary Domain Name Server (DNS) : 202.6.100.2

#CS Internet
Primary Domain Name Server (DNS) : 202.183.255.20
Secondary Domain Name Server (DNS) : 202.183.255.21

#CWN internet ( Chomanan Worldnet )
Primary Domain Name Server (DNS) : 202.74.32.3
Secondary Domain Name Server (DNS) : 202.74.32.4

#DataLine Thai
Primary Domain Name Server (DNS) : 202.80.252.1
Secondary Domain Name Server (DNS) : 202.80.252.2

#Internet Thailand
Primary Domain Name Server (DNS) : 202.44.202.2
Secondary Domain Name Server (DNS) : 202.44.202.3
Proxy Cache Server : proxy.inet.co.th Port : 8080

#Jasmine Internet ( Ji-Net )
Primary Domain Name Server (DNS) : 203.147.0.2
Secondary Domain Name Server (DNS) : 203.147.0.3

#KSC
Primary Domain Name Server (DNS) : 203.155.33.1
Secondary Domain Name Server (DNS) : 202.44.144.33
Incoming mail (POP3) : ksc.th.com or 203.155.33.38
Outgoing mail (SMTP) : ksc.th.com or 203.155.33.38

#Loxinfo
Primary Domain Name Server (DNS) : 203.146.0.20
Secondary Domain Name Server (DNS) : 203.146.0.30

#MWEB
Primary Domain Name Server (DNS) : 203.155.33.1
Secondary Domain Name Server (DNS) : 202.44.144.33

#Samart Infonet
Primary Domain Name Server (DNS) : 203.149.0.2
Secondary Domain Name Server (DNS) : 203.149.0.3

#Siam Global Access
Primary Domain Name Server (DNS) : 202.51.128.65
Secondary Domain Name Server (DNS) : 202.51.128.66

#TOT online
Primary Domain Name Server (DNS) : 203.113.93.1
Secondary Domain Name Server (DNS) : 203.113.93.2
 
#บริษัท เค เอส ซี คอมเมอร์เชียล อินเตอร์เนต จำกัด
203.155.33.1
202.44.144.33
203.155.33.3
203.155.33.44

#บริษัท ทรู อินเทอร์เน็ต จำกัด
203.144.255.71
203.144.207.29
203.144.207.49

#บริษัท กสท โทรคมนาคม จำกัด (มหาชน)
202.129.27.135
202.129.27.133

#บริษัท ทีโอที จำกัด (มหาชน)
203.113.24.199
203.113.127.199
203.113.15.99
203.113.15.100
203.113.15.133
203.113.15.143

#บริษัท อินเทอร์เน็ตประเทศไทย จำกัด (มหาชน) หรือไอเน็ต
203.150.213.1
203.150.218.161
202.44.202.2
202.44.202.3

#บริษัท ซีเอส ล็อกซอินโฟ จำกัด (มหาชน)
203.146.237.237
203.146.237.222
203.146.0.30
203.146.0.20

#บริษัท จัสมิน อินเตอร์เนต จำกัด
203.147.0.3
203.147.0.2
203.130.159.20
203.130.159.21

#บริษัท ทีทีแอนด์ที จำกัด (มหาชน)
202.69.137.131
202.69.137.132
202.69.137.83
202.69.137.84
 
##OpenDns
208.67.220.220
208.67.222.222

##GoogleDns
8.8.4.4
8.8.8.8
 
server=202.69.137.137 # Triple T Global Net 41
server=202.69.137.138 # Triple T Global Net 45
server=203.146.237.237 # csloxinfo 39
server=203.121.130.40 # Pacific 39.9
server=203.144.255.72 # asianet 40.9
server=202.44.144.33 # KSC 41.5
server=203.146.102.231 # truefaster 42.5
server=203.144.255.71 # asianet 42.8
server=202.129.27.134 # cattelecom 43.6
server=203.146.237.222 # csloxinfo 48.5
server=202.57.160.129 # Issp 48.9
server=202.6.100.1 # ABAC 50
server=203.121.130.39 # Pacific 51.5
server=203.155.33.1 # KSC 51.9
server=202.44.68.3 # Sripatum 52.7
server=203.144.207.49 # asianet (True) 54.5
server=203.144.207.29 # asianet (True) 58.1
server=202.57.128.71 # SGA 62
server=203.147.0.3 # Jasmine Internet 62.4
server=61.19.245.246 # cattelecom *
server=61.19.254.134 # cattelecom *
server=202.47.249.4 # cattelecom *
server=203.148.255.70 # A-Net *
server=203.148.255.78 # A-Net *
server=203.149.0.2 # Samart *
server=203.149.0.3 # Samart *
server=203.146.222.3 # buddybb *
server=203.158.144.1 # Rmutp *
server=203.146.64.33 # Tnet *
server=202.182.0.1 # FarEast *
server=202.182.0.2 # FarEast *
server=192.150.249.11 # Thammasat *
server=208.67.222.222 # OpenDNS 277.8
server=208.67.220.220 # OpenDNS 285.1

21 January 2011

Set Zone Time in Debian

Set Zone Time in Debian Set Zeone Time
dpkg-reconfigure tzdata
Check
date

How to kill a thread in delphi?

How to kill a thread in delphi? TMyThread Execute
procedure TMyThread.Execute;
begin
  while not Terminated do begin
    //Here you do a chunk of your work.
    //It's important to have chunks small enough so that "while not Terminated"
    //gets checked often enough.
  end;
  //Here you finalize everything before thread terminates
end;
With this, you can call
MyThread.Terminate;
There is another method, called 'forced termination'. You can call
TerminateThread(MyThread.ThreadId);

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Blog by Chagridsada Boonthus | http://chagridsada.blogspot.com/