עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

גילוי ip בשפת C

Featured Replies

פורסם

שלום לכולם,

איך אני מגלה את ה- IP של המחשב שלי באמצעות פקודות בשפת C ?

תודה!

פורסם

דבר ראשון - C לא כוללת ספריית רשת סטנדרטית, ולכן אין דרך כללית ב- C לקבל כתובת IP.

דבר שני - יכולות להיות לאותו מחשב מספר כתובות IP שונות, על כרטיסי רשת שונים או אפילו על אותו כרטיס, כלומר זו ממש לא כתובת יחידה.

על איזו פלטפורמה אתה מדבר (סביבת עבודה+קומפיילר)?

פורסם
  • מחבר

אני עובד עם ++visual c ,

ואני עושה include ל- winsock.h

תודה.

פורסם

נו, רק בגלל שעוד לא עשיתי את זה אף פעם (עם קצת עזרה מ- MSDN)

בעיקרון הפונקציה המרכזית היא GetIPAddrTable

הקטע הוא שה- buffer שאתה מעביר לה הוא למעשה MIB_IPADDRTABLE שמוקצה לגודל יותר גדול מאשר sizeof(MIB_IPADDRTABLE).

לך תבין מתכנתי microsoft...

anyways התוכנית הזו מוציאה לך את כל כתובות ה- IP של המחשב (אם אתה נמצא ברשת - תקבל לפחות 2)


#include <iostream>
#include <windows.h>
#include <tchar.h>

#include "iprtrmib.h"
#include "iphlpapi.h"

using std::cout;
using std::cerr;
using std::endl;

int _tmain(int argc, _TCHAR* argv[])
{
PMIB_IPADDRTABLE pIPAddrTable;
DWORD dwSize = 0;

pIPAddrTable = (MIB_IPADDRTABLE*) malloc( sizeof( MIB_IPADDRTABLE) );

// Make an initial call to GetIpAddrTable to get the
// necessary size into the dwSize variable
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
{
free( pIPAddrTable );
pIPAddrTable = (MIB_IPADDRTABLE *) malloc ( dwSize );
}

// Make a second call to GetIpAddrTable to get the
// actual data we want
DWORD dwRes;
if ( (dwRes = GetIpAddrTable( pIPAddrTable, &dwSize, 0 )) == NO_ERROR )
{
for(DWORD i=0;i<pIPAddrTable->dwNumEntries;i++)
{
IPAddr addr=pIPAddrTable->table[i].dwAddr;
cout<<(addr&0xFF)<<"."<<((addr&0xFFFF)>>8)<<"."<<((addr&0xFFFFFF)>>16)<<"."<<(addr>>24)<<endl;
}
free( pIPAddrTable );
}
else
{
cerr<<"Error retrieving ip addresses\n";
}
return 0;
}

פורסם

לא יודע למה שאני מהדר תתוכנית יש שגיאה:

#include "iphlpapi.h"

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.