function CheckHost(tab)
	if tab == nil then
		return nil
	end
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	local result = 0
	local hostpath = Obj:GetHostPath()
	if Obj:FileExists(hostpath)==false then
		return 0
	end
	
	local fileObj = XLGetObject("XLDoctor.FileIO.Obj")
	local lines = {} 
	local bIsInTag = false
	local handle = fileObj:Open(hostpath, "r")
	while true do
		local line = fileObj:ReadLine(handle)
		if line==nil then
			-- 读文件结束
			break
		end
		
		if string.sub(line, 1, 1) ~= '#' then	
			for i=0, #tab['rule']['domains'] do
				if tab['rule']['domains'][i]~=nil then
					local value = tab['rule']['domains'][i]['domain@']['value']
					if string.match(line, value) ~= nil and not bIsInTag then
						result = 1
					--	local strDomainName = string.match(line, "[%p%w]*$")
					--	local strIP = string.match(line, "^[%p%w]*")
					--	local objStat = XLGetObject("XLDoctor.StatHelper.Obj")
					--	objStat:AddStatStrVal("xldoctor|hosts|checkfailed|"..strDomainName, strIP)
						break
					end
				end
			end
		end		
	end
	fileObj:Close(handle)

	return result	
end
function FixHost(tab)	
	
	if tab == nil then
		return nil
	end
	--XLMessageBox("fixhost")
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	Obj:Sleep(1000)
	
--	return Obj:FixHost(tab['rule']['domain'])
	local result = 0	
	local hostpath = Obj:GetHostPath()	
	
	if hostpath == "{nil}" then return 2 end 
	local hostline = {}
	local none="none!@#$#%^"
	local i = 1
	--XLMessageBox(hostpath)
	local lines = {}
	local fileObj = XLGetObject("XLDoctor.FileIO.Obj")
	local handle = fileObj:Open(hostpath, "r")
	while true do
		local line = fileObj:ReadLine(handle)
		if line~=nil then
			hostline[i] = line
			if string.sub(line, 1, 1) ~= '#' then
				for j=0, #tab['rule']['domains'] do
					if tab['rule']['domains'][j]~=nil then
						if string.find(line, tab['rule']['domains'][j]['domain@']['value']) ~= nil then
							hostline[i] = "#"..hostline[i]
							break
						end
					end
				end
			end	
			
			i = i + 1
		else
			break
		end
	end
	
	fileObj:Close(handle)
	
	local data = ""
	for i=1, #hostline do 			
		if hostline[i] ~= none then
			if i~=#hostline then
				data = data..hostline[i].."\r\n"
			else
				data = data..hostline[i]
			end
		end
	end	
	
	local hostPathTemp = hostpath..".temp"
	
	if not Obj:WriteFile(hostPathTemp, 0, 0, 0, string.len(data), data) then
		return 1
	end
	
	if Obj:ReplaceFile(hostPathTemp, hostpath, false) == false then
		return 1
	end
	
	if Obj:DeleteFile(hostPathTemp) then
		--
	else
		--	
	end
	
	return result

end
