#include <iostream>
#include <string>
#include <xmemory>
#include <stdio.h>
#define SSID_LEN 5
using namespace std;
string exec(const char* cmd) {
char buffer[128];
string result = "";
FILE* pipe = _popen(cmd, "r");
if (!pipe) throw runtime_error("popen() failed!");
try {
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
result += buffer;
}
}
catch (...) {
_pclose(pipe);
throw;
}
_pclose(pipe);
return result;
}
int main() {
string a = exec("netsh wlan show int");
string b = "SSID";
string c = "BSSID";
string d = a.substr(a.find(b), a.find(c) - a.find(b));
string::iterator end_pos = remove(d.begin(), d.end(), ' ');
d.erase(end_pos, d.end());
string e = d.substr(SSID_LEN);
cout << "Wi-Fi adi: " << e << endl;
return 0;
}
C++ kullanarak bilgisayarın şu anda bağlı olduğu Wi-Fi'ın ismini nasıl öğrenebilirim?
Sadece Wi-Fi ismi olacak başka hiçbir bilgi değil.
Mesela "TURK_TELEKOM_5234" gibi.
Teşekkür ederim.
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
string a;
system("netsh wlan show int > C:\\users\\omerk\\desktop\\wifi.txt");
ifstream file("C:\\users\\omerk\\desktop\\wifi.txt", ios::in);
if (!file)
cout << "\nerror";
else {
while (a != "SSID") {
file >> a;
}
getline(file, a);
cout << "SSID = " << a;
file.close();
}
return 0;
}
C++:#include <iostream> #include <fstream> #include <string> #include <Windows.h> using namespace std; int main() { string a; system("netsh wlan show int > C:\\users\\omerk\\desktop\\wifi.txt"); ifstream file("C:\\users\\omerk\\desktop\\wifi.txt", ios::in); if (!file) cout << "\nerror"; else { while (a != "SSID") { file >> a; } getline(file, a); cout << "SSID = " << a; file.close(); } return 0; }
Directory olarak kendi bilgisayarınızda istediğiniz yeri seçebilrsiniz ancak aynı formatta olmalı.
Fonksiyonu çaldım. Çok az değiştirmek gerekti, kendisi de aşağıda değiştirilecek kısmı söylemiş.
Kütüphaneler kısmı sıkıntı. Sanırım Visual Studio içeriği kullanılan kütüphaneleri direkt kendisi ekliyor. Ayrı tuttuğum iki kütüphane olmadan da çalışıyor ama mesela _popen() stdio.h kütüphanesinde tanımlı. Onları o yüzden ekledim. Mesela try catch kullanmış ama exception yazdırmadığı için benim görebildiğim kadarıyla stdexcept kütüphanesine gerek yok.
Mainde ayırma kısmı string kullanımı şeklindeydi. Pek bir şey yok. Hata yapmadıysam genel kullanıma uygun olmalı.
Kod:#include <iostream> #include <string> #include <xmemory> #include <stdio.h> #define SSID_LEN 5 using namespace std; string exec(const char* cmd) { char buffer[128]; string result = ""; FILE* pipe = _popen(cmd, "r"); if (!pipe) throw runtime_error("popen() failed!"); try { while (fgets(buffer, sizeof buffer, pipe) != NULL) { result += buffer; } } catch (...) { _pclose(pipe); throw; } _pclose(pipe); return result; } int main() { string a = exec("netsh wlan show int"); string b = "SSID"; string c = "BSSID"; string d = a.substr(a.find(b), a.find(c) - a.find(b)); string::iterator end_pos = remove(d.begin(), d.end(), ' '); d.erase(end_pos, d.end()); string e = d.substr(SSID_LEN); cout << "Wi-Fi adi: " << e << endl; return 0; }
Kodu derleyip .exe aldığınızda çalışıyor. Kuzenime sadece .exe dosyasını attım ve onda çalıştı. Ama release olarak alınca çalıştı.
DLL hatalarını ikisinde de mi alıyorsunuz? Hangi IDE ile denediniz?
Peki bunu nasıl yapabilirim ? Yeni yeni alışıyorum da.Release olarak derleyip o .exe'yi çalıştırmayı deneyin.
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.